Python Variables, Data Types, Operators with basic Examples

deshmukhkartiki98 181 views 8 slides Jul 31, 2024
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

This is the basic ppt for 1st practical or lecture for Python variables, data types and operators.


Slide Content

PYTHON What is Python ? -  Python is a programming language to create the web applications. Python works on Windows, Mac, Linux, etc. Prof. Kartiki Deshmukh

Python uses new line to complete a sentence or command while other languages which often use other semicolons ; / parentheses (). Extention -> . py Comments :  # Single line comment  ' ' ' ... ' ' ' / " " " … " " "Multiple line comment. Prof. Kartiki Deshmukh

   Variables  Variable names Only contain A to Z, a to z, 0-9 and underscore. Can't start with number. Variable names are case sensitive , i.e. "Hello", "hello", "HELLO" are different. Example :  myvar =5       myvar2="John" Prof. Kartiki Deshmukh

   Data Types Variables can store data of different types, and different types can do different things. Text Type:    str Numeric Types:    int, float, complex Sequence Types:    list[], tuple(), range Mapping Type:    dict Set Types:    set, frozen set Boolean Type:    bool Binary Types:    bytes, byte array, memory view None Type:    None Type Prof. Kartiki Deshmukh

Examples of Data Types : Text Type:  str    Str => x= "Hello World!" Numeric Types:  int, float, complex     Int => x = 20   float => x= 20.5   complex => 1j Sequence Types: list, tuple, range List => x = ["apple", "banana", "cherry"] Tuple => x = ("apple", "banana", "cherry") Range => x = range(6) Mapping Type:    dict Dict =>  x = {"name" : "John", "age" : 36} Prof. Kartiki Deshmukh

Set Types:    set, frozenset Set => x = {"apple", "banana", "cherry"} Frozenset => x = frozenset ({"apple", "banana", "cherry"}) Boolean Type:    bool x = True Binary Types:    bytes, bytearray , memoryview Bytes => x = b"Hello " Bytearray => x = bytearray (5) Memoryview => x = memoryview (bytes(5)) None Type:    NoneType Nonetype => x = None We can get data type of a variable with type() function. Prof. Kartiki Deshmukh

Operators Addition Subtraction Multiplication Division Prof. Kartiki Deshmukh

Basic Syntax : if 5>2  print("Five is greater than two")  Output : Five is greater than two.  x=4 y=6 Add =  x+y print(Add) Output : 10 Prof. Kartiki Deshmukh