python introduction initial lecture unit1.pptx

ChandraPrakash715640 86 views 45 slides Apr 30, 2024
Slide 1
Slide 1 of 45
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45

About This Presentation

pyton introduction


Slide Content

GOVERNMENT POLYTECHNIC GULZARBAGH PATNA 7 INTERNET OF THINGS (Advance)

Introduction to python …… Python is a general- purpose, high- level programming language. Python was developed by Guido Van Rossum in 1989 But officially Python was made available to public in 1991. Python is recommended as first programming language for beginners

What can Python do ? Python can be used on a server to create web applications. Python can be used to create software Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics.

W . hy Python? Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). Python has a simple syntax similar to the English language. Python has syntax that allows developers to write programs with fewer lines than some other programming languages. Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. Python can be treated in a procedural way, an object-oriented way or a functional way.

Features of Python Simple and easy to learn: Freeware and Open Source: We can use python without any license High Level Programming language: Hence it is a programmer friendly language Platform Independent: Once we write a python program it can run on any platform without rewriting once again. Dynamically Typed: we are not required to declare type for variables. Extensive Library: we can use library directly and are not responsible to implement the functionality. Supporting GUI (Graphical User Interface):

It is used for : Web development (server-side), Software development, Mathematics, system scripting:- Python is widely used for writing scripts to automate tasks and processes. Operating systems Data science and machine learning Web frameworks and applications Graphic design, image processing, games, and scientific/computational applications Enterprise and business applications: Python language is being used by almost all companies like – Google, Amazon, Facebook, Instagram, Uber… etc.

Installation of python To download python, visit www.python.org Click on the Downloads tab and then select the Windows option Select the latest version Since I am using a 64bit system, I’ll select “Windows x86- 64 executable installer”. Once the executable file download is complete, you can open it to install Python. Click on Run, which will start the installation process Setup was successful.

Syntax print("Hello, World") o/p:- Hello, World Print(‘hii’) o/p:- hii X=5 Print(x) o/p:- 5

Advantages of Python Easy to Read, Learn and Write Python is a high- level programming language that has English- like syntax. This makes it easier to read and understand the code. Python is really easy to pick up and learn , that is why a lot of people recommend Python to beginners. You need less lines of code to perform the same task as compared to other major languages like C/C++ and Java . Improved Productivity Python is a very productive language . Due to the simplicity of Python, developers can focus on solving the problem. Interpreted Language Python is an interpreted language which means that Python directly executes the code line by line.

Dynamically Typed Python doesn’t know the type of variable until we run the code. It automatically assigns the data type during execution Free and Open-Source Python comes under the OSI approved open- source license. This makes it free to use and distribute Vast Libraries Support The standard library of Python is huge, you can find almost all the functions needed for your task. So, you don’t have to depend on external libraries. Portability In many languages like C/C++, you need to change your code to run the program on different platforms. That is not the same with Python. You only write once and run it anywhere.

Disadvantages of Python Slow Speed We discussed above that Python is an interpreted language and dynamically- typed language. The line by line execution of code often leads to slow execution . Not Memory Efficient The Python programming language uses a large amount of memory . This can be a disadvantage while building applications when we prefer memory optimization. Mobile Development : While Python is widely used for server- side development, web development, and data science, it is not as prominent in the field of mobile app development compared to languages like Java (for Android) or Swift (for iOS). Memory Consumption : Python's dynamic typing and automatic memory management come at a cost of higher memory consumption compared to languages like C or C++.

5. Runtime Errors As we know Python is a dynamically typed language so the data type of a variable can change anytime. A variable containing integer number may hold a string in the future, which can lead to Runtime Errors .

Variable Variable are used to store values. In python programming language no command for declaring a variable. A variable is created as soon as we assign a value to it. A Variable is the name given to a memory location in a program . Variable is container.(value store) Variable is a store reserved any location for a value. a = 30 where a=variables= container to store a value 30 b = “polytechnic” c= 71.6758

Rule of define variable 1. Not start with digits 1 = 10 ( wrong) a =10 (right) 2 .Variable name not allow space character Example- a b c = 20 (wrong) absd= 20( right) 3. Not allow special character except Underscore_ @a= 12 (wrong) _a =123 (right) 4 .Variable name should not python keywords name.

4 .Variable name should not python keywords name if=”I am smart” print(if) o/p Invalid xyz=”I am smart” print(xyz) o/p I am smart 5. Case sensitive TOTAL=999 print(total) o/p Invalid print(TOTAL) o/p 999

Reserved words in python

Datatypes in Python Data types represent the type of data present inside a variable. Based on value provided , the type will be assigned is Dynamically typed language. Text Type: str int, float, complex list, tuple, range dict Numeric Types: Sequence Types: Mapping Type: Boolean Type: bool Python contains several inbuilt function Type():- To check the type of variable print() to print the value

1. Int Datatype :- We can use int data type to represent whole numbers(integral value) Eg:- a=10 print(type(a)) o/p <class’int’> 2 Float Datatype :- we can use float datatype to represent floating point values(decimal values) Eg:- f=1.234 print(type(f)) o/p <class ‘float’>

Bool Datatype we can use this data type to represent Boolean values. The only allowed values for this data type are: True and False Python represents True as 1 and False as Example1.b=True print(type(b)) o/p <class ‘bool’> 2. True+True o/p:- 2 3. True- False o/p:- 1 3. a=10 b=15 c =a<b print(c) o/p True

Str type 2. s1=’hii’ print(s1) o/p: hiii str represents string datatype A string is a Sequence of characters enclosed within single quotes or double quotes. By using single quotes or double quotes we cannot represent multi line strings. e.g 1. s1= " hello” print(s1) o/p hello 3. thanku=”’thanku universe i am so blessed everthing is always workig out for me. i am so lucky”’ print(thanku)

Escape Characters single quote(\') a = 'ram\'s car' print(a) output:- ram's car New Line (\n) a = "Hello\nWorld" print(a) o/p:- Hello World

tab (\t) a = "Hello\tWorld" print(a) Output :- Hello World Backspace (\b) a = "Indus\b\b\bIndia" print(a) O/p :- InIndia Carriage Return(\r) a = "Indus\rIndia" print(a) o/p:- India

Backslash(\\) a = "Indus\\India\\" print(a) Output:- Indus\India\

Operators Python Operators. The operator is a symbol that performs a specific operation between two operands. OPERATORS: These are the special symbols. E.g.- + , * , /, etc. OPERAND: It is the value on which the operator is applied. Arithmetic Operators Comparison Operators or Relational Operators Logical Operators Bitwise Operators Assignment Operators Equality operators Membership Operators Identity Operators

Arithmetic Operators Python Arithmetic operators are used to perform basic mathematical operations like addition, subtraction, multiplication , and division . Arithmetic operators are used with numeric values to perform common mathematical operations:

Addition:- sum of x and y Example:- x=2 y=3 print(x+y) 0/p: - 5 Subtraction:- Difference of x and y Example:- x=4 y=3 print(x- y) o/p:- 1

Multiplication:- Product of x and y Example:- x=2 y=3 print(x*y) o/p:- 6 Division:- quotient of x and y Example:- x = 12 y = 3 Print (x / y) o/p:- 4 Modulus :- remainder of x and y x = 5 y = 2 Example:- Print (x % y) o/p:- 1

Exponent:- x to the power of y Example:- x = 2 y = 5 print(x ** y) #same as 2*2*2*2*2 o/p:- 32 Floor division:- quotient of x and y Example :- x = 15 y = 2 print(x // y) #the floor division // rounds the result down to the nearest whole number o/p:- 7

Comparison Operators. Relational operators are used for comparing the values. It either returns True or False according to the condition. These operators are also known as Comparison Operators. 1) Greater than : This operator returns True if the left operand is greater than the right operand. Syntax: x > y Example: a = 9 b = 5 print(a > b) Output: True

Less than: This operator returns True if the left operand is less than the right operand. Syntax: x < y Example: a = 9 b = 5 print(a < b) Output: False Equal to : This operator returns True if both the operands are equal i.e. if both the left and the right operand are equal to each other. Example: a = 9 b = 5 print(a == b) Output: False

4) Not equal to: This operator returns True if both the operands are not equal. Syntax: x != y Example: a = 9 b = 5 print(a != b) Output : True

5) Greater than or equal to : This operator returns True if the left operand is greater than or equal to the right operand. Syntax: x >= y Example: a = 9 b = 5 print(a >= b) Output: True

6) Less than or equal to: This operator returns True if the left operand is less than or equal to the right operand. Syntax: x <= y Example: a = 9 b = 5 print(a <= b) Output: False

Logical Operators Logical operators are used on conditional statements (either True or False). They perform Logical AND , Logical OR and Logical NOT operations. And x and y True if both x and y are True. Otherwise False. print(x=True and y=False) --- - False print(x= True and y= True) ---- True Or x or y True if either x or y are True. Otherwise False. print(x= False or y= False) --- - False print(x= True or y = False) --- - True

Not:- Complement Example 1 x=5 print(not(x>3 and x<10) o/p: False Example2 x=5 print(x> 3 or x<4) o/p : True Example3 x=5 print(x>3 and x<10) o/p: True

Assignment Operators Python assignment operators are used to assign values to variables. These operators include simple assignment operator, addition assign, subtraction assign, multiplication assign, division and assign operators etc .

Addition Assignment x = 5 x += 3 print(x) o/p:- 8 Subtraction Assignment x = 5 x - = 3 print(x) //x= x- 3 o/p:- 2

Equality operators ==, != We can apply these operators for any type even for incompatible types also Example: 1.10==20 False 2.False==False True 3.10!=True False
Tags