0% found this document useful (0 votes)
61 views

Python Chart

Python is an interpreted, high-level, general-purpose programming language. It emphasizes code readability through significant whitespace and its comprehensive standard library. It supports multiple programming paradigms including object-oriented, procedural, and functional programming. Guido van Rossum began developing Python in the late 1980s as a successor to the ABC language. Major versions 2.0 and 3.0 introduced backward-incompatible changes but 2.7 and 3.x are now the primary supported versions.

Uploaded by

Mr RuthLess
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Python Chart

Python is an interpreted, high-level, general-purpose programming language. It emphasizes code readability through significant whitespace and its comprehensive standard library. It supports multiple programming paradigms including object-oriented, procedural, and functional programming. Guido van Rossum began developing Python in the late 1980s as a successor to the ABC language. Major versions 2.0 and 3.0 introduced backward-incompatible changes but 2.7 and 3.x are now the primary supported versions.

Uploaded by

Mr RuthLess
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Python 

is an interpreted high-level general-purpose programming language. Its design


philosophy emphasizes code readability with its use of significant indentation. Its language
constructs as well as its object-oriented approach aim to help programmers write clear, logical
code for small and large-scale projects.[30]
Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms,
including structured (particularly, procedural), object-oriented and functional programming. It is
often described as a "batteries included" language due to its comprehensive standard library.[31][32]
Guido van Rossum began working on Python in the late 1980s, as a successor to the ABC
programming language, and first released it in 1991 as Python 0.9.0.[33] Python 2.0 was released
in 2000 and introduced new features, such as list comprehensions and a cycle-detecting garbage
collection system (in addition to reference counting). Python 3.0 was released in 2008 and was a
major revision of the language that is not completely backward-compatible. Python 2 was
discontinued with version 2.7.18 in 2020

Statements and control flow[edit]


Python's statements include (among others):

 The assignment statement, using a single equals sign  = .


 The  if  statement, which conditionally executes a block of code, along
with  else  and  elif  (a contraction of else-if).
 The  for  statement, which iterates over an iterable object, capturing each element to
a local variable for use by the attached block.
 The  while  statement, which executes a block of code as long as its condition is
true.
 The  try  statement, which allows exceptions raised in its attached code block to be
caught and handled by  except  clauses; it also ensures that clean-up code in
a  finally  block will always be run regardless of how the block exits.
 The  raise  statement, used to raise a specified exception or re-raise a caught
exception.
 The  class  statement, which executes a block of code and attaches its local
namespace to a class, for use in object-oriented programming.
 The  def  statement, which defines a function or method.
 The  with  statement, which encloses a code block within a context manager (for
example, acquiring a lock before the block of code is run and releasing the lock
afterwards, or opening a file and then closing it), allowing resource-acquisition-is-
initialization (RAII)-like behavior and replaces a common try/finally idiom.[80]
 The  break  statement, exits from a loop.
 The  continue  statement, skips this iteration and continues with the next item.
 The  del  statement, removes a variable, which means the reference from the name
to the value is deleted and trying to use that variable will cause an error. A deleted
variable can be reassigned.
 The  pass  statement, which serves as a NOP. It is syntactically needed to create an
empty code block.
 The  assert  statement, used during debugging to check for conditions that should
apply.
 The  yield  statement, which returns a value from a generator function
and  yield  is also an operator. This form is used to implement coroutines.
 The  return  statement, used to return a value from a function.
 The  import  statement, which is used to import modules whose functions or
variables can be used in the current program.

Python's development is conducted largely through the Python Enhancement Proposal (PEP)


process, the primary mechanism for proposing major new features, collecting community input
on issues and documenting Python design decisions.[154] Python coding style is covered in PEP 8.
[155]
 Outstanding PEPs are reviewed and commented on by the Python community and the
steering council.[154]
Enhancement of the language corresponds with development of the CPython reference
implementation. The mailing list python-dev is the primary forum for the language's development.
Specific issues are discussed in the Roundup bug tracker hosted at bugs.python.org.
[156]
 Development originally took place on a self-hosted source-code repository running Mercurial,
until Python moved to GitHub in January 2017.[157]
CPython's public releases come in three types, distinguished by which part of the version
number is incremented:

 Backward-incompatible versions, where code is expected to break and needs to be


manually ported. The first part of the version number is incremented. These releases
happen infrequently—version 3.0 was released 8 years after 2.0.
 Major or "feature" releases are largely compatible with the previous version but
introduce new features. The second part of the version number is incremented.
Starting with Python 3.9, these releases are expected to happen annually.[158][159] Each
major version is supported by bugfixes for several years after its release.[160]
 Bugfix releases,[161] which introduce no new features, occur about every 3 months and
are made when a sufficient number of bugs have been fixed upstream since the last
release. Security vulnerabilities are also patched in these releases. The third and
final part of the version number is incremented.[161]
Many alpha, beta, and release-candidates are also released as previews and for testing before
final releases. Although there is a rough schedule for each release, they are often delayed if the
code is not ready. Python's development team monitors the state of the code by running the
large unit test suite during development.[162]
The major academic conference on Python is PyCon. There are also special Python mentoring
programmes, such as Pyladies.
Python 3.10 deprecated  wstr  (to be removed in Python 3.12; meaning Python
extensions[163] need to be modified by then),[164] and added pattern matching to the language.[165]

API documentation generators[edit]


Tools that can generate documentation for Python API include pydoc (available as part of
standard library), Sphinx, Pdoc and its forks, Doxygen and Graphviz, among others.

Example:

1. print ('Hello Python')  

Output:

Hello World
Python program to do arithmetical
operations
Example -

1. # Store input numbers:  
2. num1 = input('Enter first number: ')  
3. num2 = input('Enter second number: ')  
4.   
5. # Add two numbers  
6. sum = float(num1) + float(num2)  
7. # Subtract two numbers  
8. min = float(num1) - float(num2)  
9. # Multiply two numbers  
10. mul = float(num1) * float(num2)  
11. #Divide two numbers  
12. div = float(num1) / float(num2)  
13. # Display the sum  
14. print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))  
15.   
16. # Display the subtraction  
17. print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min))  
18. # Display the multiplication  
19. print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul))  
20. # Display the division  
21. print('The division of {0} and {1} is {2}'.format(num1, num2, div))  

Output:

Enter first number: 10


Enter second number: 20
The sum of 10 and 20 is 30.0
The subtraction of 10 and 20 is -10.0
The multiplication of 10 and 20 is 200.0
The division of 10 and 20 is 0.5
The if statement
The if statement is used to test a particular condition and if the condition is true, it
executes a block of code known as if-block. The condition of if statement can be any
valid logical expression which can be either evaluated to true or false.

The syntax of the if-statement is given below.

1. if expression:  
2.     statement  

Example 1

1. num = int(input("enter the number?"))  
2. if num%2 == 0:  
3.     print("Number is even")  
Output:

enter the number?10


Number is even

Python for loop


The for loop in Python is used to iterate the statements or a part of the program
several times. It is frequently used to traverse the data structures like list, tuple, or
dictionary.

The syntax of for loop in python is given below.

1. for iterating_var in sequence:    
2.     statement(s)    

The for loop flowchart


For loop Using Sequence
Example-1: Iterating string using for loop

1. str = "Python"  
2. for i in str:  
3.     print(i)  

Output:

P
y
t
h
o
n

Python Dictionary
Python Dictionary is used to store the data in a key-value pair format. The dictionary
is the data type in Python, which can simulate the real-life data arrangement where
some specific value exists for some particular key. It is the mutable data-structure.
The dictionary is defined into element Keys and values.

Let's see an example to create a dictionary and print its content.

1. Employee = {"Name": "John", "Age": 29, "salary":25000,"Company":"GOOGLE"}  
  
2. print(type(Employee))    
3. print("printing Employee data .... ")    
4. print(Employee)    

Output

<class 'dict'>
Printing Employee data ....
{'Name': 'John', 'Age': 29, 'salary': 25000, 'Company': 'GOOGLE'}

Python NumPy
NumPy stands for numeric python which is a python package for the computation
and processing of the multidimensional and single dimensional array elements.

Travis Oliphant created NumPy package in 2005 by injecting the features of the


ancestor module Numeric into another module Numarray.

With the revolution of data science, data analysis libraries like NumPy, SciPy, Pandas,
etc. have seen a lot of growth. With a much easier syntax than other programming
languages, python is the first choice language for the data scientist.

NumPy provides a convenient and efficient way to handle the vast amount of data.
NumPy is also very convenient with Matrix multiplication and data reshaping. NumPy
is fast which makes it reasonable to work with a large set of data.

There are the following advantages of using NumPy for data analysis.

1. NumPy performs array-oriented computing.


2. It efficiently implements the multidimensional arrays.
3. It performs scientific computations.
4. It is capable of performing Fourier Transform and reshaping the data stored in
multidimensional arrays.
5. NumPy provides the in-built functions for linear algebra and random number
generation.

Python program to create a Circular Linked List


of N nodes and count the number of nodes
In this program, we have to find out the number of nodes present in the circular
linked list. We first create the circular linked list, then traverse through the list and
increment variable 'count' by 1.

PROGRAM:
1. #Represents the node of the list.    
2. class Node:    
3.     def __init__(self,data):    
4.         self.data = data;    
5.         self.next = None;    
6.      
7. class CreateList:    
8.     #Declaring head and tail pointer as null.    
9.     def __init__(self):    
10.         self.count = 0;    
11.         self.head = Node(None);    
12.         self.tail = Node(None);    
13.         self.head.next = self.tail;    
14.         self.tail.next = self.head;    
15.         
16.     #This function will add the new node at the end of the list.    
17.     def add(self,data):    
18.         newNode = Node(data);    
19.         #Checks if the list is empty.    
20.         if self.head.data is None:    
21.             #If list is empty, both head and tail would point to new node.    
22.             self.head = newNode;    
23.             self.tail = newNode;    
24.             newNode.next = self.head;    
25.         else:    
26.             #tail will point to new node.    
27.             self.tail.next = newNode;    
28.             #New node will become new tail.    
29.             self.tail = newNode;    
30.             #Since, it is circular linked list tail will point to head.    
31.             self.tail.next = self.head;    
32.                 
33.     #This function will count the nodes of circular linked list    
34.     def countNodes(self):    
35.         current = self.head;    
36.         self.count=self.count+1;    
37.         while(current.next != self.head):    
38.             self.count=self.count+1;    
39.             current = current.next;    
40.         print("Count of nodes present in circular linked list: "),    
41.         print(self.count);    
42.         
43.      
44. class CircularLinkedList:    
45.     cl = CreateList();    
46.     #Adds data to the list    
47.     cl.add(1);    
48.     cl.add(2);    
49.     cl.add(4);    
50.     cl.add(1);    
51.     cl.add(2);    
52.     cl.add(3);    
53.     #Displays all the nodes present in the list    
54.     cl.countNodes();    

Output:

Count of nodes present in circular linked list:


6
Python Tuple
Python Tuple is used to store the sequence of immutable Python objects. The tuple is
similar to lists since the value of the items stored in the list can be changed, whereas
the tuple is immutable, and the value of the items stored in the tuple cannot be
changed.

1. T1 = (101, "Peter", 22)    
2. T2 = ("Apple", "Banana", "Orange")     
3. T3 = 10,20,30,40,50  
4.   
5. print(type(T1))  
6. print(type(T2))  
7. print(type(T3))  

Output:

<class 'tuple'>
<class 'tuple'>
<class 'tuple'>

Python Set
A Python set is the collection of the unordered items. Each element in the set must
be unique, immutable, and the sets remove the duplicate elements. Sets are mutable
which means we can modify it after its creation.

 Using curly braces

1. Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", 
"Sunday"}    
2. print(Days)    
3. print(type(Days))    
4. print("looping through the set elements ... ")    
5. for i in Days:    
6.     print(i)    

Output:

{'Friday', 'Tuesday', 'Monday', 'Saturday', 'Thursday', 'Sunday',


'Wednesday'}
<class 'set'>
looping through the set elements ...
Friday
Tuesday
Monday
Saturday
Thursday
Sunday
Wednesday

You might also like