SlideShare a Scribd company logo
Introduction to Python
Python is a programming language which was created by Guido Van Rossum . It can be used to
follow both procedural approach and object-oriented approach of programming.
PYTHON BASICS  Comments : Comments are the statements which are incorporated
in the code to give a better understanding of code statements to the
user. There are two types of comments in python.
1. Single Line
2. Multi Line .
 Single Line comment A single-line comment is used to add some
explanatory text in the program for better understanding of the next
line.
 Multiline comments The multiline comments are written in python
using triple quotes. You can write number lines starting with triple
quotes and end with triple quotes.
Introduction
•CHARACTER SET:
Character set is a group of letters or signs which are
valid in a language. For example English has 26, Greek
has 24 characters, Hindi has 44 etc. And Python
Character set includes letters, sign, numbers and
symbols.
• Letters: A-Z, a-z
• Digits:0-9
• Special Symbols:_,+,-,*,/,(,),{,},[,]...etc
• White spaces: blank space, tab, carriage return,
newline etc.
TOKENS
•Token is the
smallest unit of a
program in any
programming
language. It is also
known as Lexical
Unit.
1. Keywords
•Keywords are those reserved
words for specific functioning which
provides a special meaning to
interpreter/compiler.
•The keywords can’t be used for
any other purpose than the originally
defined. Some of the keywords
displayed below:
2. Identifiers
Example on Identifiers
● Identifiers are the name given to variables, classes, methods(functions), etc. For example,
Here, language is a variable (an identifier) which holds the value 'Python'.
We cannot use keywords as variable names as they are reserved names that are
built-in to Python. For example,
The above code is wrong because we have used continue as a variable name.
2.1. Valid Identifiers
2.2. Invalid identifiers
Activity: W.A.P to declare four different type of values Example:
Value 1="Your Name"
Value 2="Age"
Value 3="Grade in Roman Number" Use print statement "sep"
and "end", to add more data.
● In Python, a variable is a container for holding values, akin to a box.
● These containers can accommodate a wide range of data types, making them versatile storage units.
● Like a physical box, you can open the variable to inspect its contents or add new data.
● Assigning a name to a variable is comparable to labelling a container, providing a means of
identification.
● These named variables can store various values, such as numbers and strings, in Python.
Variables
There are certain rules that need to be followed while naming variables in Python.
Activity: identify if these variable names are valid or not.
Advance Python Programming until operators.pdf
Create a variable and assign any numerical value. Use the print()function to display the value stored in the variable.
Assigning a value to a variable
num = 100 # create and assign a value to the variable
print(num) # display the value of the variable
Output:
100
num =100 # create and assign a value to the variable
print(num) # display the value of the variable
num =120.5 # reassign a new value to the variable
print(num) # display the variable after re-assigning
Output:
100
120.5
We can assign a value of a variable to another variable. Create another variable, num2, and assign the
variable num2 to num1.
Assigning a value to a variable
num1 = 100 # assign a value to the variable num1
num2 = num1 # assign the value of num1 to the variable
num2
print("num2 :", num2) # display the variable
Output:
num2 :100
● The input() function is used to get input from the user.
User input in Python
● Get a string as user input and assign it to the new variable name.
User input in Python
name = input("Enter your name: ")
● Write a code to greet the user.
print("Welcome ", name)
● Click Run and enter any name.
Output:
Enter your name: Arthur
Welcome Arthur
Data types
Data types represent the type of data that any variable holds in its memory. We will
use the following data types in this module.
Data types
Let’s write a program to find the sum of 10 and any other number entered by a user.
# program to find the sum of two numbers
number1 = input("Enter the number: ")
number2 = 10
# display the sum
print("The sum is ", number1 + number2)
Output:
Feedback:
Incompatible types
You used an addition operation with a string and a number on line 4.
But you can't do that with that operator. Make sure both sides of the
operator are the right type.
Data types
Typecasting
Even if you enter an integer value, the input() function converts it into a string. You
need to convert it into an integer in your code using typecasting.
Convert the input to integer data type using int() function.
# program to find the sum of two numbers
number1 = int(input("Enter the number: "))
number2 = 10
# display the sum
print("The sum is ", number1 + number2)
Output:
Enter the first number: 2
The sum is 12
Literals are the values
which are saved in
variables/identifiers,
and they cannot be
changed.
Punctuators
Used to implement the grammatical structure of Syntax.
Python Operators
• Operators are special symbols or keywords used to perform operations on variables and
values.
• Think of them like mathematical signs or logical tools.
Example:
a = 10
b = 5
print(a + b)
Advance Python Programming until operators.pdf
Advance Python Programming until operators.pdf
Advance Python Programming until operators.pdf
Advance Python Programming until operators.pdf
Arithmetic Operators
a = 10
b = 3
print("Arithmetic Operators:")
print("a + b =", a + b)
print("a - b =", a - b)
print("a * b =", a * b)
print("a / b =", a / b)
print("a % b =", a % b)
print("a ** b =", a ** b)
print("a // b =", a // b)
a = 10
b = 3
print("Comparison Operators:")
print("a == b:", a == b)
print("a != b:", a != b)
print("a > b:", a > b)
print("a < b:", a < b)
print("a >= b:", a >= b)
print("a <= b:", a <= b)
Comparison Operators
Activity
Assignment Operators
a = 10
b = 3
print("Assignment Operators:")
x = 5
print("Initial x =", x)
x += 3
print("x += 3 →", x)
x *= 2
print("x *= 2 →", x)
x -= 4
print("x -= 4 →", x)
x /= 2
print("x /= 2 →", x)
Logical Operators
a = 10
b = 3
print(" Logical Operators:")
print("a > 5 and b < 5:", a > 5 and b < 5)
print("a < 5 or b < 5:", a < 5 or b < 5)
print("not(a > b):", not(a > b))
Activity
THANK YOU

More Related Content

PPTX
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
PDF
PPTX
1-Introduction to Python, features of python, history of python(1).pptx
PPTX
Introduction to learn and Python Interpreter
PPTX
Python basics
PPTX
Python knowledge ,......................
PPTX
Introduction on basic python and it's application
PDF
Python-01| Fundamentals
python notes for MASTER OF COMPUTER APPLIICATION_ppt.pptx
1-Introduction to Python, features of python, history of python(1).pptx
Introduction to learn and Python Interpreter
Python basics
Python knowledge ,......................
Introduction on basic python and it's application
Python-01| Fundamentals

Similar to Advance Python Programming until operators.pdf (20)

PPTX
unit1.pptx for python programming CSE department
PPTX
Chapter1 python introduction syntax general
PPTX
1691912901477_Python_Basics and list,tuple,string.pptx
PPT
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
PDF
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
PPTX
Python (Data Analysis) cleaning and visualize
PPTX
Learn about Python power point presentation
PDF
Python Interview Questions PDF By ScholarHat.pdf
PPTX
Python Guide.pptx
PPTX
Python 3.pptx
PPTX
python
ODP
Python slide.1
PPTX
11-unit1chapter02pythonfundamentals-180823043011.pptx
PPTX
unit (1)INTRODUCTION TO PYTHON course.pptx
DOCX
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
PPTX
PDF
3-Python Python oho pytho hdiwefjhdsjhds
PPTX
Keep it Stupidly Simple Introduce Python
PDF
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
unit1.pptx for python programming CSE department
Chapter1 python introduction syntax general
1691912901477_Python_Basics and list,tuple,string.pptx
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
Python (Data Analysis) cleaning and visualize
Learn about Python power point presentation
Python Interview Questions PDF By ScholarHat.pdf
Python Guide.pptx
Python 3.pptx
python
Python slide.1
11-unit1chapter02pythonfundamentals-180823043011.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
3-Python Python oho pytho hdiwefjhdsjhds
Keep it Stupidly Simple Introduce Python
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
Ad

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
GDM (1) (1).pptx small presentation for students
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Pre independence Education in Inndia.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O7-L3 Supply Chain Operations - ICLT Program
Supply Chain Operations Speaking Notes -ICLT Program
GDM (1) (1).pptx small presentation for students
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Complications of Minimal Access Surgery at WLH
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf
Computing-Curriculum for Schools in Ghana
Microbial diseases, their pathogenesis and prophylaxis
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Pre independence Education in Inndia.pdf
Ad

Advance Python Programming until operators.pdf

  • 1. Introduction to Python Python is a programming language which was created by Guido Van Rossum . It can be used to follow both procedural approach and object-oriented approach of programming.
  • 2. PYTHON BASICS  Comments : Comments are the statements which are incorporated in the code to give a better understanding of code statements to the user. There are two types of comments in python. 1. Single Line 2. Multi Line .  Single Line comment A single-line comment is used to add some explanatory text in the program for better understanding of the next line.  Multiline comments The multiline comments are written in python using triple quotes. You can write number lines starting with triple quotes and end with triple quotes.
  • 3. Introduction •CHARACTER SET: Character set is a group of letters or signs which are valid in a language. For example English has 26, Greek has 24 characters, Hindi has 44 etc. And Python Character set includes letters, sign, numbers and symbols. • Letters: A-Z, a-z • Digits:0-9 • Special Symbols:_,+,-,*,/,(,),{,},[,]...etc • White spaces: blank space, tab, carriage return, newline etc.
  • 4. TOKENS •Token is the smallest unit of a program in any programming language. It is also known as Lexical Unit.
  • 5. 1. Keywords •Keywords are those reserved words for specific functioning which provides a special meaning to interpreter/compiler. •The keywords can’t be used for any other purpose than the originally defined. Some of the keywords displayed below:
  • 7. Example on Identifiers ● Identifiers are the name given to variables, classes, methods(functions), etc. For example, Here, language is a variable (an identifier) which holds the value 'Python'. We cannot use keywords as variable names as they are reserved names that are built-in to Python. For example, The above code is wrong because we have used continue as a variable name.
  • 10. Activity: W.A.P to declare four different type of values Example: Value 1="Your Name" Value 2="Age" Value 3="Grade in Roman Number" Use print statement "sep" and "end", to add more data.
  • 11. ● In Python, a variable is a container for holding values, akin to a box. ● These containers can accommodate a wide range of data types, making them versatile storage units. ● Like a physical box, you can open the variable to inspect its contents or add new data. ● Assigning a name to a variable is comparable to labelling a container, providing a means of identification. ● These named variables can store various values, such as numbers and strings, in Python. Variables
  • 12. There are certain rules that need to be followed while naming variables in Python.
  • 13. Activity: identify if these variable names are valid or not.
  • 15. Create a variable and assign any numerical value. Use the print()function to display the value stored in the variable. Assigning a value to a variable num = 100 # create and assign a value to the variable print(num) # display the value of the variable Output: 100 num =100 # create and assign a value to the variable print(num) # display the value of the variable num =120.5 # reassign a new value to the variable print(num) # display the variable after re-assigning Output: 100 120.5
  • 16. We can assign a value of a variable to another variable. Create another variable, num2, and assign the variable num2 to num1. Assigning a value to a variable num1 = 100 # assign a value to the variable num1 num2 = num1 # assign the value of num1 to the variable num2 print("num2 :", num2) # display the variable Output: num2 :100
  • 17. ● The input() function is used to get input from the user. User input in Python
  • 18. ● Get a string as user input and assign it to the new variable name. User input in Python name = input("Enter your name: ") ● Write a code to greet the user. print("Welcome ", name) ● Click Run and enter any name. Output: Enter your name: Arthur Welcome Arthur
  • 19. Data types Data types represent the type of data that any variable holds in its memory. We will use the following data types in this module.
  • 20. Data types Let’s write a program to find the sum of 10 and any other number entered by a user. # program to find the sum of two numbers number1 = input("Enter the number: ") number2 = 10 # display the sum print("The sum is ", number1 + number2) Output: Feedback: Incompatible types You used an addition operation with a string and a number on line 4. But you can't do that with that operator. Make sure both sides of the operator are the right type.
  • 21. Data types Typecasting Even if you enter an integer value, the input() function converts it into a string. You need to convert it into an integer in your code using typecasting. Convert the input to integer data type using int() function. # program to find the sum of two numbers number1 = int(input("Enter the number: ")) number2 = 10 # display the sum print("The sum is ", number1 + number2) Output: Enter the first number: 2 The sum is 12
  • 22. Literals are the values which are saved in variables/identifiers, and they cannot be changed.
  • 23. Punctuators Used to implement the grammatical structure of Syntax.
  • 24. Python Operators • Operators are special symbols or keywords used to perform operations on variables and values. • Think of them like mathematical signs or logical tools. Example: a = 10 b = 5 print(a + b)
  • 29. Arithmetic Operators a = 10 b = 3 print("Arithmetic Operators:") print("a + b =", a + b) print("a - b =", a - b) print("a * b =", a * b) print("a / b =", a / b) print("a % b =", a % b) print("a ** b =", a ** b) print("a // b =", a // b) a = 10 b = 3 print("Comparison Operators:") print("a == b:", a == b) print("a != b:", a != b) print("a > b:", a > b) print("a < b:", a < b) print("a >= b:", a >= b) print("a <= b:", a <= b) Comparison Operators Activity
  • 30. Assignment Operators a = 10 b = 3 print("Assignment Operators:") x = 5 print("Initial x =", x) x += 3 print("x += 3 →", x) x *= 2 print("x *= 2 →", x) x -= 4 print("x -= 4 →", x) x /= 2 print("x /= 2 →", x) Logical Operators a = 10 b = 3 print(" Logical Operators:") print("a > 5 and b < 5:", a > 5 and b < 5) print("a < 5 or b < 5:", a < 5 or b < 5) print("not(a > b):", not(a > b)) Activity