0% found this document useful (0 votes)
13 views25 pages

heena

Uploaded by

junedmohammed517
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)
13 views25 pages

heena

Uploaded by

junedmohammed517
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
You are on page 1/ 25

CONTENT

Certificate i
Acknowledgement ii
Declaration iii
Abstract iv
Chapter 1: INTRODUCTION 1
Chapter 2: EXECUTION STEPS 4
2.1: Interactive Shell 5
2.2: Executable or Script Files. 6
2.3: User Interface or Ide 9
Chapter 3: DATA TYPE’S AND OPERATONS 10
3.1: Number 10
3.2: Strings 11
3.3: List 12
3.4: Tuple 13
3.5: Dictionary 14
Chapter 4: STATEMENTS AND SYNTAX IN PYTHON 15
4.1: Operators 15
4.1.1: Assignment Operators 15
4.1.2: Arithmetic Operators 15
4.1.3: Comparison Operators 16
4.1.4: Logical Operators 16
4.1.5: Identity Operators 17
4.1.6: Membership Operators 17
4.1.7: Bitwise Operators 17
4.2: CONDITIONAL STATEMENTS 18
4.2.1: IF Condition 18
4.2.2: IF-Else Condition 18
4.2.3: IF-Elif-Else ladder 19
4.3: LOOPS 20
4.3.1: While Loop 20
4.3.2: For Loop 20
4.3.3: Nested Loop 21
Conclusion 23
References 24
Chapter 1
INTRODUCTION
In the mid-1980s a Dutch fellow named Guido van Rossum was working on an educational
project to build a language for new coders called ABC. As a result of working on this
project, Van Rossum became interested in language design, and that’s when he started
working on Python. He made some unusual decisions, which really set Python apart from
the zeitgeist at that time, and continue to make the language special today.

One of Van Rossum’s decisions was to make indentation meaningful, which is unusual in
programming languages. Critics who thought this would make the language hard to use
didn’t receive the idea very well, but this feature is part of the reason why Python is both
readable and popular. Python syntax is very similar to English, so it’s intuitive, which
helps you understand what’s going on. You don't have to look up what symbols mean
when you use Python. The language constructs enable the user to write clear programs on
both a small and large scale.

The most important feature in Python being it supports multiple programming paradigms,
including object-oriented, imperative and functional programming or procedural styles.
Python supports a dynamic type system and automatic memory management and has a
large and comprehensive standard library. Python's development is conducted largely
through the Python Enhancement Proposal (PEP) process.

The PEP process is the primary mechanism for proposing major new features, for
collecting feedback on an issue, and for documenting the design decisions that have gone
into Python. Outstanding PEPs are commented and reviewed by the Python Community.

The Python interpreter is easily extended with new functions and data types implemented
in C or C++ (or other languages callable from C). Python is also suitable as an extension
language for customizable applications.

Python is a widely used

 general-purpose
 interpreted
 dynamic programming language.
1
FEATURES OF PYTHON

Easy to code

Python is high level programming language. Python is very easy to learn language as
compared to other language like c, c#, java script, java etc. It is very easy to code in python
language and anybody can learn python basic in few hours or days. It is also developer-
friendly language.

Free and Open Source

Python language is freely available at official website since, it is open-source; this means
that source code is also available to the public. So, you can download it as, use it as well
as share it.

Object-Oriented Language

One of the key features of python is Object-Oriented programming. Python supports


object-oriented language and concepts of classes, objects encapsulation etc.

GUI Programming Support

Graphical Users interfaces can be made using a module such as PyQt5, PyQt4, wxPython
or Tk in python. PyQt5 is the most popular option for creating graphical apps with Python.

High-Level Language

Python is a high-level language. When we write programs in python, we do not need to


remember the system architecture, nor do we need to manage the memory.

Extensible feature

Python is a Extensible language. We can write some python code into c or c++ language
and also, we can compile that code in c/c++ language.

Python is Portable language

Python language is also a portable language for example, if we have python code for
windows and if we want to run this code on other platform such as Linux, UNIX and Ma
2
then we do not need to change it, we can run this code on any platform.

Python is Integrated language

Python is also an integrated language because we can easily integrated python with other
language like c, c++ etc.

Interpreted Language

Python is an Interpreted Language because python code is executed line by line at a time
like other language c, c++, java etc there is no need to compile python code this makes it
easier to debug our code. The source code of python is converted into an immediate form
called byte code.

Large Standard Library

Python has a large standard library which provides rich set of module and functions so
you do not have to write your own code for every single thing. There are many libraries
present in python for such as regular expressions, unit testing, web browsers etc.

Dynamically Typed Language

Python is dynamically-typed language. That means the type (for example- int, double,
long etc) for a variable is decided at run time not in advance because of this feature we
don’t need to specify the type of variable

3
Chapter 2
EXECUTION STEPS
When we compile a Python program, the python compiler converts the Python source
code into another code called byte code. Byte code is a fixed set of instructions that
represent different types of operations. This code can run on any Operating System and
hardware. So mainly, byte code instructions are platform-independent.
The size of each byte code instruction is one byte, and that's why they are called the name
byte code.

Now we need to convert the byte code to machine understandable code, which
comprises 0s and 1s. This machine understandable code is called machine code.

So Python uses an interpreter called PVM (Python Virtual Machine), which understands
the byte code and converts it into machine code.

4
We can view the python byte code files (.pyc).
First, write a program in any text editor and save it with .py
now, compile the program using python compiler.

for example, if your file name is test.py, then use the following syntax
c:\> python test.py

To see the byte code instructions created by the python compiler before they are executed
by the PVM, execute the following command.

c:\>python -m dis test.py

Here -m represents the module named dis. This module is also known as 'disassembler'
that displays the byte code in the human-understandable format.

The above command will display the byte code of the test.pyc file creates during the
compilation of the test.py file.

Interactive shell
The term "interactive" traces back to the Latin expression "inter agere". The verb "agere"
means amongst other things "to do something" and "to act", while "inter" denotes the
spatial and temporal position to things and events, i.e., "between" or "among" objects,
persons, and events. So "inter agere" means "to act between" or "to act among" these.

With this in mind, we can say that the interactive shell is between the user and the operating
system (e.g. Linux, Unix, Windows or others). Instead of an operating system an
interpreter can be used for a programming language like Python as well. The Python
interpreter can be used from an interactive shell.

5
The interactive shell is also interactive in the way that it stands between the commands or

actions and their execution. In other words, the shell waits for commands from the user,
which it executes and returns the result of the execution. Afterwards, the shell waits for
the next input

A shell in biology is a calcium carbonate "wall" which protects snails or mussels from its
environment or its enemies. Similarly, a shell in operating systems lies between the kernel
of the operating system and the user. It's a "protection" in both directions. The user doesn't
have to use the complicated basic functions of the OS but is capable of using the interactive
shell which is relatively simple and easy to understand. The kernel is protected from
unintentional and incorrect usages of system functions.

Python offers a comfortable command line interface with the Python Shell, which is also
known as the "Python Interactive Shell". It looks like the term "Interactive Shell" is a
tautology, because "shell" is interactive on its own

Executable or script file

Although running a Python script using the terminal or your favorite text editor is
straightforward, there are some situations in which you will prefer to hide all the code
written in the script (.py) inside an executable file (.exe).

Maybe you need to send the script to someone who doesn’t code at all or you might need
to schedule a job that runs a.exe at a specific time on your computer. Whatever the situation.

There are two ways to create an executable file

The first option offers a nice GUI (graphical user interface) that takes care of all the stuff
necessary to convert your Python script into an executable file.

6
To install the last version of auto-py-to-exe, just open up a terminal and run the following
command.
 pip install auto-py-to-exe

Once you install auto-py-to-exe, making an executable file is as easy as writing the
following command.

 Auto-py-to-exe

Browse the script you wish to convert and add it to the “Script Location” field

Feel free to choose any script you want. However, if your script needs to read a path make
sure that you use absolute paths since relative paths won’t behave as you might expect with
executable files. If necessary, include the following line of code below to know where the
executable file is located and make the necessary changes to your script so you read/export
files on the right directory.

application path = os.path.dirname(sys.executable)

Step 2: Choosing “One Directory” or “One File”

Now we have to choose whether we want to create “one directory” or “one file.” The first
creates a directory with all the dependencies your script needs to run (including the
executable file), while the second creates only a single executable file.

Step 3. Choosing “Console Based” or “Window Based”

Now it’s time to choose whether the console will be displayed or not. If you choose
“Console Based,” the console will open after running the executable file, which is
recommended if your script generates console-based outputs. However, if you don’t want
to show the console outputs when running the executable file, choose “Window Based”

Step 4: Advanced options (e.g., output directory, additional imports)

7
You can add an icon, add files that your script needs to run, and more! However, for this
example, I’ll only modify the path where the executable file will be exported. To do so,
click on the “Setting” option and browse the output directory you wish.

Step 5: Convert the file

To convert the .py file to .exe just click the blue button you see below.

Something really important that auto-py-to-exe shows above the convert button is the
code that pyinstaller (the main library and second option in this guide to make .exe files)
needs to create an executable file behind that fancy GUI you see on the screen.

Once the process is finished the executable file should be located in the output directory
you set in step 4!

Making an Executable file with PyInstaller

This option fits better for those who prefer to quickly create an executable file running a
command on the terminal.

If you’re used to working with the terminal, then the PyInstaller library will be the best
option. To install PyInstaller follow these steps.

 Step 1: Open up a terminal and run pip install pyinstaller

 Step 2: Using the terminal, go to the directory where your script is located
(use the cd command)

8
 Step 3: Once you‘re in the right directory, write a command with the
following syntaxpyinstaller --onefile name_of_script.py in the terminal to
make the script executable.

The command used in step 3 is similar to the code shown in the step 5 picture for the
auto-py-to-exe option. You can play a little bit with the GUI offered by auto-py-to-exe to
get used to the many options you can add to this command.

After running the command, you should see a message that says “completed
successfully.” In the directory where your script is located, a folder named “dist” should
have been created. Inside the folder, you’ll find the standalone executable!

User interface or Idle

DLE is Python's Integrated Development and Learning Environment. IDLE has the

following features: coded in 100% pure Python, using the tkinter GUI toolkit. cross-

platform: works mostly the same on Windows, Unix, and macOS.

9
Chapter 3

DATA TYPES AND OPERATIONS


A data type, in programming, is a classification that specifies which type of value a
variable has and what type of mathematical, relational or logical operations can be applied
to it without causing an error.

3.1 : Numbers
Number data types store numeric values. They are immutable data types, which means
that changing the value of a number data type results in a newly allocated object.

Different types of Number data types are :

 int
 float
 complex

Int type
int (Integers) are the whole number, including negative numbers but not fractions. In
Python, there is no limit to how long an integer value can be.

num = -8

# print the data type

print(type(num))

output

<class 'int'>

Float type
This is a real number with floating-point representation. It is specified by a

10
decimal point. Optionally, the character e or E followed by a positive or

negative integer may be appended to specify scientific notation. . Some


examples of numbers that are represented as floats are 0.5 and -7.823457.

They can be created directly by entering a number with a decimal point, or


by using operations such as division on integers. Extra zeros present at
the number’s end are ignored automatically.

num = 3/4

# print the data type

print(type(num))

output
<class 'float'>

Complex type
A complex number is a number that consists of the real and imaginary parts. For
example, 2 + 3j is a complex number where 2 is the real component, and 3 multiplied by
j is an imaginary part.

num = 6 + 9j

print(type(num))

output

<class 'complex'>

11
3.2 strings

Strings in python are surrounded by either single quotation marks, or double quotation
marks.

'hello' is the same as "hello".

You can display a string literal with the print() function:

print("Hello")
print('Hello')

output
HelloHello

Assign value to a variable

Assigning a string to a variable is done with the variable name followed by an equal sign
and the string:

a = "Hello"
print(a)

output
Hello

Multiline Strings

You can assign a multiline string to a variable by using three quotes:

12
“And they were moving closely

Thinking they would never see the sun again"""

print(a)

Output
And they were moving closely

Thinking they would never see the sun again

3.3 List

Lists are used to store multiple items in a single variable.

Lists are one of 4 built-in data types in Python used to store collections of data, the other
3 are Tuple, Set, and Dictionary, all with different qualities and usage.Lists are created
using square brackets:

thislist = ["apple", "banana", "cherry"]


print(thislist)

output

["apple", "banana", "cherry"]

list items are ordered, changeable, and allow duplicate values.

List items are indexed, the first item has index [0], the second item has index [1] etc.

Ordered

When we say that lists are ordered, it means that the items have a defined
order, and that order will not change.

13
If you add new items to a list, the new items will be placed at the end of
the list.

Changeable

The list is changeable, meaning that we can change, add, and remove
items in a list after it has been created.

Allow Duplicates

Since lists are indexed, lists can have items with the same value:

thislist = ["apple", "banana", "cherry", "apple", "cherry"]


print(thislist)

output

["apple", "banana", "cherry", "apple", "cherry"]

3.4 Tuple

Tuples are used to store multiple items in a single variable. Tuple is one of 4 built-in
data types in Python used to store collections of data, the other 3 are List, Set, and
Dictionary, all with different qualities and usage. A tuple is a collection which is ordered
and unchangeable.

to create a tuple we will use () operators.

Eg:

Var = (“Geeks”, “for”, “Geeks”)

Print(var)

14
Output
(“Geeks” , ”for” , ”Geeks”)

3.5 Dictionary

Dictionaries are used to store data values in key:value pairs.

A dictionary is a collection which is ordered*, changeable and do not allow duplicates.

Thisdict = { “brand”: “Ford”,

“model”: “Mustang”,

“year”: 1964}

Print(thisdict)

Output {

“brand”: “Ford”,

“model”: “Mustang”,

“year”: 1964

15
Chapter 4
STATEMENTS AND SYNTAX IN PYTHON
4.1 : Operators

Operators are used to perform operations on values and variables. These are the special
symbols that carry out arithmetic, logical, bitwise computations. The value the operator
operates on is known as Operand.

4.1.1 Assignment Operation

4.1.2: Arithmetic operator

16
4.1.3: Comparisons operator

4.1.4: Logical operator

17
4.1.5 Identity operator

4.1.6: Membership operator

4.1.7: Bitwise operator

18
4.2 : Conditional Statements

Python supports the usual logical conditions from mathematics:

 Equals: a == b
 Not Equals: a != b
 Less than: a < b
 Less than or equal to: a <= b
 Greater than: a > b
 Greater than or equal to: a >= b

4.2.1: If statement

A = 33

B = 200

If b > a:

Print(“b is greater than a”)

Output B is greater than a

4.2.2: if-else Statement

Number = 10

If number > 0:

Print(‘Positive number’)

Else:

Print(‘Negative number’)

Output
Positive number

19
4.2.3: if-elif condition
If 51<5:

Print(“False, statement skipped”)

Elif 0<5:

Print(“true, block executed”)

Elif 0<3:

Print(“true, but block will not execute”)

Else:

Print(“If all fails.”)

Output True, block executed

4.3 Loops

4.3.1 While loop


With the while loop we can execute a set of statements as long as a condition is true.
I=1
While I < 6:
Print(i)
I += 1

1
Output
2

20
4.3.2: For loop

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a
set, or a string).

This is less like the for keyword in other programming languages, and works more like an
iterator method as found in other object-orientated programming languages.

With the for loop we can execute a set of statements, once for each item in a list, tuple, set
etc.

Fruits = [“apple”, “banana”, “cherry”]

For x in fruits:

Print(x)

apple
Output
banana

cherry

4.3.3: Nested loop

In Python programming language there are two types of loops which are for loop and while
loop. Using these loops we can create nested loops in Python. Nested loops mean loops
inside a loop. For example, while loop inside the for loop, for loop inside the for loop, etc.

21
CONCLUSION

Python is a easy to use language which is freely available

Python objects and functions are very versatile

Python is a very high level object oriented programming language

It the juices 50% of time required by developers

22
REFERENCES

[1] http://www.w3schools.com/python/

[2]http://www.geeksforgeeks.com/python/

23

You might also like