Byte to Code-1.1-Python Programming Fundamentals.pptx
Byte to Code-1.1-Python Programming Fundamentals.pptx
What is Python?
Python is a high-level object-oriented programming language that was created by Guido van
Rossum. It is also called general-purpose programming language as it is used in almost every
domain we can think of as mentioned below:
❑ Web Development
❑ Software Development
❑ Game Development
❑ AI & ML
❑ Data Analytics
An Introduction to Python
Why Python Programming?
IEEE spectrum list of top programming language 2021. The list of programming languages is based on popularity.
An Introduction to Python
Java C++
C# Python
Installing Python
Installing Python
Installing Python
Installing PyCharm
Installing PyCharm
Your First Python Program
Your First Python Program
Variables
Variable is a name that is used to refer to memory location. It stores and manipulates data.
Variables are entities of a program that holds a value. Here is an example of a variable:
x=100
In the below diagram, the box holds a value of 100 and is named as x. Therefore, the variable is
x, and the data it holds is the value.
Data Types
Dynamic Types
Python is a dynamically typed language. It doesn’t know about the type of the variable
until the code is run.
x=6
print(type(x))
x = 'hello'
print(type(x))
Conditional Statements
Conditional Statements:
Conditional statements allow a program to make decisions based on certain conditions. They are fundamental in all
programming languages. Here's a quick overview using Python.
if If……else If……elif……else
Conditional Statements
Example
if If……else If……elif……else
i = 10 i = 20 i = 20
if i < 15: if i == 10:
if i > 15: print("i is smaller than 15") print("i is 10")
print("10 is less than 15") print("i'm in if Block") elif i == 15:
print("I am Not in if") else: print("i is 15")
print("i is greater than 15") elif i == 20:
print("i'm in else Block") print("i is 20")
print("i'm not in if and not in else Block") else:
print("i is not present")
Logical Operators
and
a = 10
b = 10
c = -10
or not
a = 10 a = 10
b = -10
c=0 if not (a%3 == 0 or a%5 == 0):
print("10 is not divisible by either 3 or 5")
if a > 0 or b > 0: else:
print("Either of the number is greater than 0") print("10 is divisible by either 3 or 5")
else:
print("No number is greater than 0")
if b > 0 or c > 0:
print("Either of the number is greater than 0")
else:
print("No number is greater than 0")
Comparison/Relational/Conditional Operators
Comparison/Relational/Conditional Operators
Example:
a=9
b=5
print(a > b)
print(a < b)
print(a == b)
print(a != b)
print(a >= b)
print(a <= b)
Loops
While Loops : A while loop statement in Python programming language repeatedly executes a target
statement as long as a given condition is true.
count = 0
while count < 9:
print('The count is:', count)
count = count + 1
print("Good bye!")
Sum of n Numbers Program
while i <= n:
sum = sum + i
i = i +1
print(sum)
Break & Continue Statement
Break Continue
i=1 i=0
while i < 6: while i < 6:
print(i) i += 1
if i == 3: if i == 3:
break continue
i += 1 print(i)
sum = 0
while True:
num = input("Enter a Number: ")
if num == "quit":
break
try:
num = int(num)
except:
print("Enter a valid number please.")
continue
sum = sum + num
print(sum)
For Loops
For Loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
For Loops
for x in adj:
for y in fruits:
print(x, y)
Strings
Strings are List like many other popular programming languages. Python does not have a character data type,
a single character is simply a string with a length of 1. Square brackets can be used to access elements of the
string.
a = "Hello World"
print(a)
print(a[0])
print(a[-1])
print(a[0:3])
print(a[0:])
print(a[1:])
print(a[:4])
print(a[0:-1])