Python-Introduction:
What is Python?
Python is a high-level, interpreted, and general-purpose programming language.
Here, High level means : language that is similar to English, making it easier for humans to
read and write.
It’s called interpreted because you don’t need to compile it before running — you just write
and execute your code, and Python interprets it line by line.
Python reads and executes your code line by line, like how you read and follow a recipe
one step at a time , no need to “compile” it first like C or Java.
Why do we need Python?
● It is simple and beginner friendly.
● It is a cross platform (i.e. it works on windows,Mac, Linux)
● It is an open source
● It can be used in various domains like: Machine learning, Web development, Data
science, Cyber Security, Game development, IOT.
Advantages of Python:
● Easy to learn and read.
● Interpreted language
● Cross Platform
● Open source
● Extensive libraries like Numpy,Pandas,Matplotlib
● Versatile
● Works well with C,C++,Java i.e. Integration Friendly
Who uses Python?
Google,Netflix,Youtube,Instagram,NASA,Tesla,Amazon,Reddit,Spotify.
Real Life Use Cases :
● Machine Learning and AI : Predicting diseases, chatbots, face recognition, hate
speech detection.
● Data Science and Analytics : Analyzing sales data, predicting stock prices.
● Web development : Building websites using frameworks like Django or Flask.
● Automation / Scripting : Automating emails, cleaning files, downloading data
automatically.
● Learn the difference between print ( total ) and print ( “ total “ )
print(total) → prints the value stored in the variable total
print("total") → prints the text total literally
total=23
print(total)
print("total")
Comments in python :
# Single line comment
""" This is a multi-line comment
and will not be printed """
Variables and Data types:
Variables : Variables are the names that are used to store data in memory.
name = "Ram"
age = 45
height = 6.2
is_student = False
print(name, age, height, is_student)
● Check data types of the following variables
print(type(name))
print(type(age))
print(type(height))
print(type(is_student))
Common Data types:
String -> str -> “Ram” # text
Integer -> Int -> 45 # whole value
Bool -> True/ False #logical value
Float -> 3.14 # decimal number
Taking Input from user :
● By using the input() function we can take input from the user.
● By default input() type is string.
● Using split() we can take multiple inputs at once in python.
age=input()
print(age)
print(type(age))
But to use it as a number:
age=int(input())
print(age)
print(type(age))
Basic Arithmetic Operations:
+,-,*,/
// (floor division) : divides a by b and then rounds down to nearest whole number
% (modulus) : returns the remainder.
** (power) : a**b i.e. 2**2 is 4
a = 10
b = 3
print("Add:", a + b)
print("Sub:", a - b)
print("Mul:", a * b)
print("Div:", a / b)
print("Floor Div:", a // b)
print("Remainder:", a % b)
print("Power:", a ** b)