0% found this document useful (0 votes)
2 views5 pages

Basic

The document provides an overview of variables, keywords, and identifiers in Python. It explains the rules for naming variables and identifiers, including the use of reserved keywords and syntax errors that can occur when these rules are violated. Additionally, it covers how to assign single and multiple values to variables and the implications of variable naming conventions.

Uploaded by

ayushnale
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Basic

The document provides an overview of variables, keywords, and identifiers in Python. It explains the rules for naming variables and identifiers, including the use of reserved keywords and syntax errors that can occur when these rules are violated. Additionally, it covers how to assign single and multiple values to variables and the implications of variable naming conventions.

Uploaded by

ayushnale
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Variable :

In [ ]:

1 Variable is name given to the Memory Location


2 Varible is container to store the values
3

keywords

In [ ]:

1 reserved words which can not be used as variables

In [2]:

1 import keyword
2 help('keywords')

Here is a list of the Python keywords. Enter any keyword to get more hel
p.

False class from or


None continue global pass
True def if raise
and del import return
as elif in try
assert else is while
async except lambda with
await finally nonlocal yield
break for not

In [5]:

1 and=200

Cell In[5], line 1


and=200
^
SyntaxError: invalid syntax
In [7]:

1 print([Link])

['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'brea


k', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finall
y', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlo
cal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yi
eld']

In [8]:

1 None="Amol"

Cell In[8], line 1


None="Amol"
^
SyntaxError: cannot assign to None

Identifiers

In [ ]:

1 Name of Variable / function / class

Rules for Identifiers

In [ ]:

1 1. a-z , A-Z , _ , 0-9


2 2. starts with only alphabates or _
3 3. white spaces not allowed
4 4. keywords can not be used as indetifiers

In [15]:

1 price=459
2 price

Out[15]:

459

In [12]:

1 _price=909
In [16]:

1 Price=9768.9078 # Python is case sensitive price and Price both are diff
2 Price

Out[16]:

9768.9078

In [17]:

1 1price=45.78

Cell In[17], line 1


1price=45.78
^
SyntaxError: invalid decimal literal

In [20]:

1 /price=45.78

<>:1: SyntaxWarning: 'float' object is not callable; perhaps you missed a


comma?
<>:1: SyntaxWarning: 'float' object is not callable; perhaps you missed a
comma?
C:\Users\HP\AppData\Local\Temp\ipykernel_15700\[Link]: SyntaxWar
ning: 'float' object is not callable; perhaps you missed a comma?
price=45.78()

-------------------------------------------------------------------------
--
TypeError Traceback (most recent call las
t)
Cell In[20], line 1
----> 1 price=45.78()

TypeError: 'float' object is not callable

In [21]:

1 first_name="Amir Khan"

In [22]:

1 firstname="Amir Khan"
In [23]:

1 first name="Amir Khan"

Cell In[23], line 1


first name="Amir Khan"
^
SyntaxError: invalid syntax

In [24]:

1 first3name="Amir Khan"

In [25]:

1 firstname12345="Amir Khan"

In [26]:

1 fir6st4na_me="Amir Khan"

In [27]:

1 9fir6st4na_me="Amir Khan"

Cell In[27], line 1


9fir6st4na_me="Amir Khan"
^
SyntaxError: invalid decimal literal

Exporing Variables

Assigning Single Value to the Varaible

1 a=780
2 print(f"Value of a is {a}")

In [29]:

1 a=b=780
2 print(f"Value of a is {a} Value of b is {b}")

Value of a is 780 Value of b is 780

Assigning multiple values to the multiple variables


In [ ]:

1 a,b,c=500,600,700
2 # a=500
3 # b=600
4 # c=700
5
6 print(f"Value of a is {a} Value of b is {b} Value of c is {c}")
7 type(a)

In [32]:

1 a,b,c=900

-------------------------------------------------------------------------
--
TypeError Traceback (most recent call las
t)
Cell In[32], line 1
----> 1 a,b,c=900

TypeError: cannot unpack non-iterable int object

Assiginning multiple values to single Variable

In [ ]:

1 x=100,300,600 # tuple
2 type(x)

In [ ]:

You might also like