8/7/25, 5:15 PM Untitled
1. Comments:- is a non-executable piece of code used to
increase the readability of the program.
Comments are of 2 types:
1. Single-line comment: are denoted with '#'
2. Multi-line comment: are denoted with triple quotations('''...'''
or """....""")
In [2]: # qwertyuiop
In [6]: """this
is
a
multi-line
comment"""
Out[6]: 'this\nis\na \nmulti-line\ncomment'
In [4]: 23456+4567
Out[4]: 28023
this is a raw cell where we can use this as multiline comment.
Keywords:- are the predefined or reserved words in our
python library.
Python have 35+ keywords.
In [7]: help("keywords")
Here is a list of the Python keywords. Enter any keyword to get more help.
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 [ ]: break # words which are green and bold are keywords
help() # words which are green & have () are predefined
# functions
var # words in black color are variables.
'a',"hello",'''qwweery''',"""1234567"""
# any text present within quotations & are red in color
# are valid string in python.
localhost:8888/doc/tree/Desktop/MCCAI-8th/Untitled.ipynb 1/5
8/7/25, 5:15 PM Untitled
3. Identifiers:- these are the names that we give to a class,
variable, function etc., inorder to identify them.
The Naming convention rule of an Identifier is known as
"Identifier's Rule".
In [8]: # Rule 1: cannot use any keywords as Identifier's name.
break = 121435
Cell In[8], line 2
break = 121435
^
SyntaxError: invalid syntax
In [9]: # Rule 2: cannot start an Identifier's Name with digits.
12var = 'apple'
Cell In[9], line 2
12var = 'apple'
^
SyntaxError: invalid decimal literal
In [10]: # Rule 3: cannot use spaces in between identifier's name.
var one = 'apple'
Cell In[10], line 2
var one = 'apple'
^
SyntaxError: invalid syntax
In [11]: # Rule 4: cannot use any special characters except '_'.
var@1 = 'apple'
Cell In[11], line 2
var@1 = 'apple'
^
SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?
In [12]: var_1 = 'apple'
In [13]: # Rule 5: Python is a case-sensitive language 'A' != 'a'
a = 'apple'
print(A)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[13], line 3
1 # Rule 5: Python is a case-sensitive language 'A' != 'a'
2 a = 'apple'
----> 3 print(A)
NameError: name 'A' is not defined
localhost:8888/doc/tree/Desktop/MCCAI-8th/Untitled.ipynb 2/5
8/7/25, 5:15 PM Untitled
In [15]: # Correct Way for Identifier's Name:
# start the name with alphabet which can be followed by
# digits and to separate multiple words use '_'.
var12_one = 'apple'
Variables:- are like some containers that allow us to store
values in it. It is also used for memory allocation.
Must follow Identifier's Rule while naming.
Dynamic Typing - variables are declared without any datatype for
which in python a variable is able to store any kind of data
without any restrictions.
In [23]: var = 'apple'
In [24]: print(var)
apple
In [25]: var
Out[25]: 'apple'
In [26]: var1 = 10
print(var1)
10
In [27]: var
Out[27]: 'apple'
In [28]: var1
Out[28]: 10
4. Datatypes: the kind of data we are dealing with.
In [30]: # 1. Primary Datatype:
# Numeric Datatype:
# int: all integer values from -infinity to +infinity
var1 = 12345678990
type(var1)
Out[30]: int
In [31]: # float: decimal values
var2 = 1234567.0
type(var2)
localhost:8888/doc/tree/Desktop/MCCAI-8th/Untitled.ipynb 3/5
8/7/25, 5:15 PM Untitled
Out[31]: float
In [32]: # complex: real(a) & imaginary value(bj) -> (a+bj)
var3 = 56+88j
type(var3)
Out[32]: complex
In python the imaginary number is always represented using 'j'
alphabet other than this no other alphabets are valid.
In [33]: var3 = 56+88i
type(var3)
Cell In[33], line 1
var3 = 56+88i
^
SyntaxError: invalid decimal literal
In [34]: # Non-Numeric Datatype:
# bool: boolean values i.e: True & False
var4 = True
type(var4)
Out[34]: bool
In [35]: # string: denoted using any quotation mark.
s1 = '12323'
type(s1)
Out[35]: str
In [36]: s2 = "qwerty"
type(s2)
Out[36]: str
In [37]: s3 = '''wqteqwytu'''
type(s3)
Out[37]: str
In [38]: s4 = """A"""
type(s4)
Out[38]: str
In [39]: # Sequential Datatype:
# list:- collection of indivisual elements separated by ,
# and enclosed within [].
x = [12,45,657,'apple',True]
type(x)
localhost:8888/doc/tree/Desktop/MCCAI-8th/Untitled.ipynb 4/5
8/7/25, 5:15 PM Untitled
Out[39]: list
In [40]: # tuple:- collection of indivisual elements separated by ,
# and enclosed within ().
t = (12,45,657,'apple',True)
type(t)
Out[40]: tuple
In [41]: # set:- collection of indivisual elements separated by ,
# and enclosed within {}.
s1 = {'apple','dove',89,78+77j}
type(s1)
Out[41]: set
In [42]: # dictionary: collection of paired (key&value) elements
# separated by , and enclosed within a {key:value,key:value,..}
d = {1:'apple',2:'mango','b':'boy',True:78+99j}
type(d)
Out[42]: dict
In [ ]:
localhost:8888/doc/tree/Desktop/MCCAI-8th/Untitled.ipynb 5/5