1 of 38

Python 

Michael Sadgun Rao K

Assistant Professor

CSE, PVPSIT

2 of 38

Keywords, Variables and Constants

Rules for Identifiers

    • letters,digits, underscore only
    • upper case and lower case are different
    • no space
    • should start with letter or underscore only
    • Keywords should not be used as identifier

Keywords - reserved words

3 of 38

Keywords – Reserved Words

4 of 38

Data Types in Python 

5 of 38

Python Literals

https://www.scaler.com/topics/python/literals-in-python/

6 of 38

String Literals in Python

7 of 38

Numeric Literals in Python

8 of 38

Numeric Literals in Python

9 of 38

Boolean Literals

10 of 38

Typecasting

11 of 38

Chr() & ord()

12 of 38

Output Function – print()

13 of 38

format() function to print only specified digits after decimal point

14 of 38

Input Function

15 of 38

Split() function on string

16 of 38

Operators - Arithmetic operators

https://www.geeksforgeeks.org/python-operators/

17 of 38

Operators - Comparison operators

https://www.geeksforgeeks.org/python-operators/

18 of 38

Operators - Logical

https://www.geeksforgeeks.org/python-operators/

19 of 38

Operators - Bitwise

20 of 38

Operators - Bitwise

Identity Operators

Membership Operators

21 of 38

22 of 38

Control Statements in python

  1. Selection Statements / branching
  2. Iteration Statements / loops
  3. Jump statements

23 of 38

24 of 38

Selection statements / branching

  1. if statements
  2. if - else statements
  3. elif statements
  4. elif ladder

25 of 38

if statements

26 of 38

if - else statements

27 of 38

elif statements

28 of 38

elif ladder

29 of 38

while loop

30 of 38

while loop - example

31 of 38

for loop

32 of 38

for loop example

33 of 38

Functions in Python

34 of 38

Functions in Python

35 of 38

Keyword Arguments - Functions in Python

  • No need to follow order of arguments
  • should specify name of the argument along with the actual argument value.

36 of 38

Arbitrary Arguments - Functions in Python

  • Arbitrary Arguments, *args, and **kwargs can pass a variable number of arguments to a function using special symbols.
  • There are two special symbols:
    1. *args in Python (Non-Keyword Arguments)
    2. **kwargs in Python (Keyword Arguments)

37 of 38

Non Keyword (*args )Arbitrary Arguments - Functions in Python

  • Arbitrary arguments ⇒ variable-length arguments
  • *args ⇒ Non-Keyword Arguments

38 of 38

Arbitrary Arguments (**kwargs) - Functions in Python

  • **kwargs - variable Keyword Arguments in Python