0% found this document useful (0 votes)
2 views14 pages

Python Cdu

Python is a high-level, general-purpose programming language created by Guido Van Rossum in 1989 and released to the public in 1991. It is recommended for beginners due to its simple syntax and versatility, being applicable in areas such as web development, data analysis, and machine learning. Key features include being free and open-source, platform-independent, and supporting both procedural and object-oriented programming paradigms.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

Python Cdu

Python is a high-level, general-purpose programming language created by Guido Van Rossum in 1989 and released to the public in 1991. It is recommended for beginners due to its simple syntax and versatility, being applicable in areas such as web development, data analysis, and machine learning. Key features include being free and open-source, platform-independent, and supporting both procedural and object-oriented programming paradigms.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming : Programming languages are a set of instructions provided to a machine and converted to machine-

readable code.
(or)
The programming language is the one way of a communication between Humans and Machine

Software : Software is a set of instructions to the hardware.

Code : The instructions that we write to create software is called Code.

Introduction of Python

 Python is a general purpose high level programming language.

 Python was developed by Guido Van Rossam in 1989 while working at National Research Institute at Netherlands.

 But officially Python was made available to public in 1991.

 Python is recommended as first programming language for beginners.

 the name of the Python programming language comes from an old BBC television comedy sketch series called Monty
Python's Flying Circus.

Where we can use Python in Real time ( or ) applications:

We can use everywhere. The most common important application areas are :
1. For developing Desktop Applications
2. For developing web Applications
3. For developing database Applications
4. For Network Programming
5. For developing games
6. For Data Analysis Applications
7. For Machine Learning
8. For developing Artificial Intelligence Applications
9. For IOT

Difference of Compiler and Interpreter :


Features of Python:
1. Free and opensource
2. Platform Independent
3. Easy to learn
4. Dynamic language
5. Interpreted language
6. High level programming language
7. Portability
8. Both procedure Language and object oriented programming Language.

 Free and Open Source: Python is available for free, and its source code can be modified and
distributed by anyone.
 Platform Independent: Python can run on various operating systems without requiring modifications to the
code.
 Easy to Learn: Python has a simple syntax that is easy for beginners to understand and use.
 Dynamic Language: Python allows for dynamic typing, meaning variable types can change at runtime.
 Interpreted Language: Python code is executed line-by-line by an interpreter, allowing for immediate execution
and testing.
 High-Level Programming Language: Python abstracts complex details of the computer hardware, making it
easier to write and understand code.

 :
Portability Python programs can be easily transferred and run on different machines without modification.
 Both Procedure and Object-Oriented Programming: Python supports multiple programming paradigms,
including procedural and object-oriented programming styles.

Python ‘Hello world ‘ print syntax :

Why Python :
 Python is an easy to learn, powerful programming language. With Python, it is possible to create programs with minimal
amount of code. Look at the code in Java and Python used for printing the message "Hello World".

KeyWords / reserved / in-built variables / Pre-Defined:

 The words are showing different but the meaning is same which is called keywords .
 In Python some words are reserved or inbuilt words to represent some meaning or functionality. Such type of words are
called Reserved words.
 There are 35 reserved words available in Python.

How To Display all keywords in our’s Console or Laptop :


 Fundamental : True ,False,None
 Logical : and ,or ,not , is
 Exception handling : try ,except, finally ,raise,assert
 Iterative : for ,while
 Transfer statements : break ,continue,pass
 Conditional : if ,else , elif
 Function & Class: from , import , class ,def ,as ,global ,nonlocal ,del ,lambda ,with , return , yield , in

Except the following 3 reserved words, all contain only lower case alphabet symbols. True False None

Variables :
The variables is nothing but its defined or declared by the manually and its holding or stroing some values .

Identifiers Concept :
A name in Python program is called identifier. It can be class name or function name or module name or variable name or any name.
Rules :
1. Alphabet Symbols (Either Upper case OR Lower case)
2. If Identifier is start with Underscore (_) then it indicates it is private.
3. Identifier should not start with Digits.
4. Identifiers are case sensitive.
5. We cannot use reserved words as identifiers Eg: def=10
6. There is no length limit for Python identifiers. But not recommended to use too lengthy identifiers.
7. Dollor ($) Symbol is not allowed in Python

If you observe above the examples 6,7 these two are keywords so , keywords are not accepted to the variables. 1 , is the starting with
digits so it’s also not variable, 4 is also not variable whybecause of it does have doller symbole.

Operators :
[Link] Operator ( + , - ,* , / , % , // , **)
2. Logical Operator ( and , or , not )
3. Relational Operator ( == ,<= ,>= ,<!=,>!=,-------)
4. Bitwise Operator ( Bitwise Or (|) ,Bitwise And (&) , Bitwise Xor (^) ,
Bitwise Not , Left << Shift ,Right Shift >> )
5. Assignment Operator ( +=,-=,*=,/=,//=,-----)
[Link] Operator ( in , not in)
7. Identity Operator ( is , is not )
Flow Control / Loops concept :
3.
Conditional Statements:
----------------------------------------

if – Used to check a condition. If the condition is True, the code inside the if block
runs.
elif – Short for "else if". It checks multiple conditions, one after another.

else – Runs when the if condition or Else coditions are False.


Iterative statements : In Python, the iterative statements are also known as looping statements or
repetitive statements. The iterative statements are used to execute a part of the program repeatedly as
long as a given condition is True.

For loop: For loop is used to iterate over a sequence (range,list,tuple,set,array,string) of items.

While: While loop is used to repeatedly execute a block of statements while a condition is true.
Transfer Statements : break ,continue ,pass

Break : 'Break' in Python is a loop control statement. It is used to control the sequence of the loop. Suppose you want to
terminate a loop and skip to the next code after the loop; break will help you do that.

Continue: The continue statement in Python is used to skip the current iteration and remaining itererations code will be execute.

Pass : The pass statement is used as a placeholder for future [Link] the pass statement is executed, nothing
happens.
Data types :
It specifies the type of data that the variable can store like integer, character, floating, double, etc. And
Each data type requires different amounts of memory.
Python is dynamically typed, meaning you don’t need to declare variable types explicitly.

Data type Description Example C/Java size Python [Link]

char Single character (Not a ‘A’ 1 byte 1 byte (depends on


separate type in Python, encoding)
stored as a string)
string Sequence of characters “ hello “ Varies 49 bytes + characters
(Text) (depends on
length)
byte Immutable sequence of b”hello” 1 byte per Varies (1 byte per
bytes element character)
int Whole numbers 100 4 bytes 28 bytes (varies with
(Positive/Negative) value)
short 2 bytes Not explicitly available
in Python
float Floating-point numbers 10.5 4 bytes 24 bytes
(Decimal numbers)
decimal High precision floating- Decimal(‘10.5’) Varies Varies (Depends on
point numbers (Used for (depends on precision)
financial calculations) precision)
boolean True or False values True/False 1 byte 28 byte
complex Real and imaginary 2+10j 8 bytes (C) 32 bytes

Fundamental Datatypes are :

1. Int
2. Float
3. String
4. Boolean
5. Complex
Complete Type Casting Table in Python

As per the Python Dataypes Flow chart is :


List:
------
1. The list is a collection elements and every element which is called single entity. That means list is group single elements
and every element separated by comma with in the squere brackets.
2. List is the heterogeneous elements , that means it contains different data types elements.
3. Insertion order preserved and it allows duplicate values.
4. List is the dynamic because based on our requirement we can increase the size and decrease the size of list.
5. List support index order and slice, and list is the mutable nature it means we can manipulate the data easily.

Tuple:
------------
Tuple is exactly same as List except that it is immutable. i.e once we creates Tuple object,we
cannot perform any changes in that object. Hence Tuple is Read Only version of List.
Set:
If we want to represent a group of unique values as a single entity with in curly braces then we should go for set.
1. Duplicates are not allowed.
2. Insertion order is not preserved.
3. Indexing and slicing not allowed for the set.
4. Heterogeneous elements are allowed.
5. .Set objects are mutable i.e once we creates set object we can perform any changes in that
object based on our requirement.
6. We can apply mathematical operations like union,intersection,difference etc on set objects

You might also like