0% found this document useful (0 votes)
2 views31 pages

Byte to Code-1.1-Python Programming Fundamentals.pptx

The document provides an introduction to Python programming, covering its history, installation, and basic syntax including variables, data types, and control structures like conditional statements and loops. It emphasizes Python's versatility as a high-level, object-oriented language used in various domains such as web development and AI. The document also includes examples of Python code for better understanding of concepts like logical operators and string manipulation.

Uploaded by

tanzim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views31 pages

Byte to Code-1.1-Python Programming Fundamentals.pptx

The document provides an introduction to Python programming, covering its history, installation, and basic syntax including variables, data types, and control structures like conditional statements and loops. It emphasizes Python's versatility as a high-level, object-oriented language used in various domains such as web development and AI. The document also includes examples of Python code for better understanding of concepts like logical operators and string manipulation.

Uploaded by

tanzim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

ByteToCode

An Introduction to Python &


Basic Python Syntax
By Md Reja E Rabbi Tonmoy
Agenda

A Brief History of Python Versions


Installing Python
Variables
Data Types
Dynamic Types
Conditional Statements (if/else/elif)
Logical Operators
Comparison/Relational/Conditional Operators
Loops
Strings
An Introduction to Python

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

Python is easy to understand

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

if a > 0 and b > 0:


print("The numbers are greater than 0")

if a > 0 and b > 0 and c > 0:


print("The numbers are greater than 0")
else:
print("At Least one number is not greater than 0")
Logical Operators

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

n = int(input("Enter the n Number:"))


sum = 0
i=1

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

#Looping Through a String #Looping Through a list #The break Statement


#Exit the loop when x is "banana"
for x in "banana": fruits = ["apple", "banana", "cherry"]
print(x) for x in fruits: fruits = ["apple", "banana", "cherry"]
print(x) for x in fruits:
print(x)
if x == "banana":
break
#The continue Statement
#Do not print banana:

fruits = ["apple", "banana", "cherry"]


for x in fruits:
if x == "banana":
continue
print(x)
For-While Comparison
while for
num = [10, 20, 30, 40, 50] num = [10, 20, 30, 40, 50]
index = 0 for x in num:
n = len(num) print(x)
while index < n:
print(num[index])
index = index+1
Nested Loops

adj = ["red", "big", "tasty"]


fruits = ["apple", "banana", "cherry"]

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])

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy