Programming With Python
Programming With Python
PRESENTED BY:
SACHIN KUMAR
ROLL NO. =1873720044
ELECTRICAL ENGINEERING
CONTENTS
1. About Python.
2. Using the Python Interpreter IDLE
3. Various valid arithmetic expressions and implementation in IDLE are
4. Features of Python.
5. Python Interfaces
6. Data types and variables
7. Operators.
8. Numeric data types
9. Sequence data type
10. Decision Making.
11. Control Flow.
12. Constructing module and packages.
13. Object-oriented program
About Python
1. Easy to code.
2. Free and Open Source
3. Object and Oriented Language
4. GUI Programming Support
5. High-Level Language
6. Extensible feature
7. Python is Portable language
8. Python is Integrated language
Python Interfaces
Python Shell – running 'python' from the Command Line opens this interactive
shell.
For the exercises, we'll use IDLE, but you can try them all and pick a
favorite.
Data types and variables
Operators
1. Operators are used to perform operations on variables and Operators are the
main building block of any programming language. Operators allow the
programmer to perform different kinds of operations on operands values.
2. Example:
print(10+5)
Python divides the operators in the following groups:
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
P Search for anything
Bitwise operators
Numeric data types
Any representation of data which has numeric value. Python identifies three types of numbers
integer, float and complex number.
• Integer
Positive and negative whole numbers .
Examples: 1234, -234, 0x46 (hexadecimal number), 00123 (octal number)) Note: In C and related
programming languages such as Python, a hexadecimal number is prefixed with Ox and an octal
number is prefixed with 0 or O.
• Float
Real numbers with a floating point representation in which the fractional component is
denoted by a decimal or scientific notation Examples:-55.550,0.005,1.32E10 (scientific notation)
• Complex number
A number with a real and imaginary component is represented
as a+bj in Python where a and b are floats and j=V-1
Examples:4+6j,-2.3+6.4j
Sequence data type
In Python, sequence is the ordered collection of similar or different data types. Sequences
allows to store multiple values in an organized and efficient fashion. There are several
sequence types in Python
String
List
Tuple
String
In python, strings are arrays of bytes representing Unicode characters. A string is a
collection of one or more characters put in single-quote, double quote or triple-quote.
In python there is no character data type, a character is a string of length one. It is
represent by str class. Strings in Python can be created using single quotes or double
quotes or even triple quotes.
Exa: Input:
my_string = 'Hello' print (my string)
my_string = "Hello" print(my_string)
my_string=**Hello** print (my_string)
Output:
Hello
Hello
Hello
Dictionary data type
• Dictionary in Python is an unordered collection of data values, used to store
data values like a map, which unlike other Data Types that hold only single
value as an element, Dictionary holds key:value pair. Key-value is provided in
the dictionary to make it more optimized. Each key-value pair in a Dictionary
is separated by a colon :, whereas each key is separated by a 'comma’.
• Creating Dictionary: A dictionary can be created by placing a sequence of
elements within curly{} braces, seperated by 'comma'. value in the dictionary
is of any datatype and can be duplicated, whereas keys can't be repeated and
must be immutable. Dictionary can be created by built-in function dict(). An
empty dictionary can be created by placing it to curly braces{}.
Input Output:
Decision Making
1. Decisions in a program are used when the program has conditional choices
to execute a code block. Let's take an example of traffic lights, where
different colors of lights lit up in different situations based on the conditions
of the road or any specific rule.
If statement
if else statements
nested if statements
If-elif ladder
Using conditionals
Programs using if, if- else and elif
A program to check if a number is positive and print the message
Control Flow