2/5/25, 11:30 AM 2. predefined keywords.
ipynb - Colab
keyboard_arrow_down TOPICS : PREDEFINED KEYWORDS
#First program
print("Hello World")
Hello World
Variables identifiers: variables is like placeholders where we kept variety of data
keyboard_arrow_down which can use to write logic. Variable is reserved memory space for storing value.
* Numbers>> integers/float
* Characters>> string
* True/false>> Boolean
* None>>none
a =2
print(type(a))
<class 'int'>
b = 2.3
print(type(b))
<class 'float'>
c = "hello"
print(type(c))
<class 'str'>
d = True
print(type(d))
<class 'bool'>
e = False
print(type(e))
<class 'bool'>
# True = 1
# False = 0
True + False
1
True - False
1
https://colab.research.google.com/drive/1cSb9jcxnbRw8G_PZZv69MfIq1oMieclh?authuser=2 1/5
2/5/25, 11:30 AM 2. predefined keywords.ipynb - Colab
True * False
0
True / False # Error because 0 / 1 is not defined
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-22-f8487d9d0863> in <cell line: 0>()
----> 1 True / False
ZeroDivisionError: division by zero
f = None
f # nothing to print
print(type(f))
<class 'NoneType'>
g = 1 + 2j
print(type(g))
<class 'complex'>
print(g.real)
1.0
print(g.imag)
2.0
Rules of defining a variables
* A variable name can contain only alphabates or digits or underscore(‘_’).
* A variable can start with only alphabates or underscore(‘_’).
* No space is used in variable name.
Comments: code will not executed,
* For single line comments- ‘#’
* For multiple line comments used- on the starting line use “““ or ‘‘‘(three open double or
single inverted commas) and on the ending line use ” ” ” or ’ ’ ’(three open double or
single inverted commas).
Keywords: keywords are predefined words that holds a special meaning and have
keyboard_arrow_down special purpose.
........
https://colab.research.google.com/drive/1cSb9jcxnbRw8G_PZZv69MfIq1oMieclh?authuser=2 2/5
2/5/25, 11:30 AM 2. predefined keywords.ipynb - Colab
keyboard_arrow_down Here is a list of the Python keywords. Enter any keyword to get more help.
#Indentation>> more readble
if 3 > 2 :
print("greater")
greater
a = 3 #statement >> fundamental block of code
statment can be of many types>> expression, assignment, condition statments, loop
name = "Mohit"
keyboard_arrow_down assignment statement
a=5
a = 5 #assignment
b = 4 #assignment
a+b #expression statement
#input output>>if you want some user to give value of variable
name = input("please enter your name: ")
please enter your name: mohit
print(name)
mohit
print(type(name))
<class 'str'>
https://colab.research.google.com/drive/1cSb9jcxnbRw8G_PZZv69MfIq1oMieclh?authuser=2 3/5
2/5/25, 11:30 AM 2. predefined keywords.ipynb - Colab
num = input("please enter your num: ")
please enter your num: 2
print(num)
print(type(num))
2
<class 'str'>
input actually take every value as a string
keyboard_arrow_down we can convert '2' as int
you can convert 2(str) as 2(int) by using Type casting
Type casting> cast means to change the format
num = int(num)
print(type(num))
<class 'int'>
a = "3.5"
type(a)
str
print(float(a))
3.5
print(type(a))
<class 'str'>
b = "108"
print(type(b))
<class 'str'>
b = int(b)
print(b)
print(type(b))
108
<class 'int'>
bool(0)
False
bool(1)
True
https://colab.research.google.com/drive/1cSb9jcxnbRw8G_PZZv69MfIq1oMieclh?authuser=2 4/5
2/5/25, 11:30 AM 2. predefined keywords.ipynb - Colab
a = "Ajay"
int(a)
# error bcoz str alphabates does not convert in int
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-43-9981c55bfe95> in <cell line: 0>()
1 a = "Ajay"
----> 2 int(a)
3 # error bcoz str alphabates does not convert in int
ValueError: invalid literal for int() with base 10: 'Ajay'
#python is case sensitive programming language
a = 1
A = 11
print(a)
print(A)
1
11
#variables should not be keywords
print("hello")
hello
print = "Ajay" # then if you want to print another word
print(“Hello”) # it will throw error
File "<ipython-input-46-e065f41a6924>", line 2
print(“Hello”) # it will throw error
^
SyntaxError: invalid character '“' (U+201C)
https://colab.research.google.com/drive/1cSb9jcxnbRw8G_PZZv69MfIq1oMieclh?authuser=2 5/5