Session1 Python Programming
Session1 Python Programming
ipynb - Colab
Welcome to Python tutorial. For your benefit we have broken down the entire tutorial into
multiple parts so that you can take it step by step. Please learn Python in the sequence of the
notebooks and topic wise as per the Table Of Contents.
Table of contents
1. Python Keywords
2. Identifiers
3. Comments in Python
4. Python Indentation
5. Python Statement
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 1/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
#To extract all keywords in python 3.12 use the below code
import keyword
print(keyword.kwlist)
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
print(python_version())
3.10.12
keyboard_arrow_down 2. Identifiers
Identifiers (also referred to as names) is given to entities like class, functions, variables etc. in
Python. It helps differentiating one entity from another.
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 2/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
100
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-9-773fd1812949> in <cell line: 1>()
----> 1 breaks == 1 # Cannot use keyword as identifiers
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-12-dca3419a1ce1> in <cell line: 1>()
----> 1 hello@hello == 10 #can't use special symbols as an identifier
hello123 = 50
print('variable2: ',hello123)
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 3/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
hello_1 = "hi"
print('variable3: ',hello_1)
variable1: 10
variable2: 50
variable3: hi
print("welcome to python")
welcome to python
This is one of the best way to convey the idea behind the code and people
reusing your code can easily make sense of your code
10
b=10
c=9
d="hi"
print(b)
print(c)
print(d)
10
9
hi
# You can write multiple lines of comment by putting a '#' at the beginning
keyboard_arrow_down Docstring
Docstring is short for documentation string.
"""
A better option to write multi line comment is by adding all your
text between a set of 3-single or 3-double quotes. Like we have done here
"""
'\nA better option to write multi line comment is by adding all your \ntext between
a set of 3-single or 3-double quotes. Like we have done here\n'
'''
A better option to write multi line comment is by adding all your
text between a set of 3-single or 3-double quotes. Like we have done here
'''
def square(num):
"""
Function to square a number.
Print this docstring using __doc__ attribute of the function
"""
return num * num
print(square(20))
400
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 5/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
A code block (body of a function, loop etc.) starts with indentation and ends with the first
unindented line. The amount of indentation is up to you, but it must be consistent throughout
that block.
Generally four whitespaces are used for indentation and is preferred over tabs.
Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the
indentation level of the line, which in turn is used to determine the grouping of statements.
variable1 = 10
variable2 = 20 # Logical continuation disrupted
variable1 = 10
variable2 = 20
variable1 = 10
variable2 = 20
print("end")
1
hello
2
hello
3
hello
end
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 6/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
print(number)
print(num)
10
(12, 23, 24, 25)
number = 10 + 20 + \
30 + 40 + \
50
#num1=10
#num2=20
#num3=30
#num4=40
print(number)
150
sum=num1+num2+num3+num4+num5
print(sum)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-27-ea5659dbbb23> in <cell line: 1>()
----> 1 sum=num1+num2+num3+num4+num5
2 print(sum)
number = (10 + 20 +
30 + 40 +
50)
print(number)
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 7/8
11/26/24, 7:42 PM Python_INTERN_001.ipynb - Colab
150
https://colab.research.google.com/drive/1-6i1h3-f-dCUCiBlzhXCR3sNZvUqVGri#scrollTo=uSleNdz0iTnN&printMode=true 8/8