PYTHON(DAY 2)
variables and literals
Variable is a name that is used to refer to memory location. Python variable is also known as an identifier and used to hold value.
In Python, we don’t need to specify the type of variable because it is smart enough to get variable type.
Python variables are more like pointers that point to memory location of our literals.
There are few rules and regulations to name a variable, these rules are naming conventions of a variable
The rules as follows:
- Name should start with an alphabet or an underscore(_).
EX: abc, _xyz, a_b_c
2. Variable name should not start with a digit or with any other special symbol.
EX: $abc, 123abc
3. Variable name should not contain spaces.
EX: a bc, 1 23
4. we should not use a variable that changes color after giving a space, because those may be keywords or words that have special meaning or task assigned to them.
EX: print, return… etc
Variable Declaration:
variable declaration can be done as follows
x = 5;
print(x)
Here, “x” is a variable that points to the memory location where the value is stored
Comments in python
comments are used to write quick notes in our code
In python there are 2 types of comments
1) single line comments
2) Multi line comments
>> Single line comments are used by using hash infront of the text or code and it does not execute when we run a program
EX:
# line 1
# line 2
# a = b+c
>> Multi line comments are used for documentation purpose like doc strings
>> multi line comments are enclosed within triple single quotes (or) triple double quotes
>> these comments executes at the time of execution
EX:
''' line1
line2
line3 '''
No comments:
Post a Comment