Variables

Variable Declaration in Python

Used to declare a variable which holds a value.


Syntax
variable_name = value
variable_name = None #to initialize without a value

Notes

Variables in Python are dynamically typed, which means a type does not have to be specified, and the variable's type can be changed.

Variable scoping in Python follows the LEGB rule, which is Local (assigned within a function), Enclosing function local (name in local scope of all enclosing functions), Global (available in the entire file), and Built-In (built into the Python library).


Example
length = 5

< Import Module   |   Lists >

© 2019 SyntaxDB. All Rights Reserved.