Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python

Python is a high-level, general-purpose programming language created by Guido Van Rossum, known for its simplicity and versatility. It is free and open-source, supports multiple operating systems, and is widely used in various complex applications by major organizations. The document also covers downloading, installing Python, and basic programming concepts such as keywords, data types, variables, and operators.

Uploaded by

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

Python

Python is a high-level, general-purpose programming language created by Guido Van Rossum, known for its simplicity and versatility. It is free and open-source, supports multiple operating systems, and is widely used in various complex applications by major organizations. The document also covers downloading, installing Python, and basic programming concepts such as keywords, data types, variables, and operators.

Uploaded by

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

Python

Introduction: -
1. Python is a general purpose high level language.
2. Developed by Guido Van Rossum in the late 1980’s
3. Presently administered by Python Software Foundation.
4. Easy to understand and learn for beginners.
5. It is highly useful (powers) some of its world’s most complex applications and
websites.
6. Google, New York Stock Exchange, Industrial Light & Magic, Intel, Cisco, HP, IBM,
NASA, and I-robot.

Feature of Python: -
1. Python is free and open-source software. Source code is available for the user.
Available under the GNO, General Public License, GPL.
2. Easy to learn and use.
3. Interpreter based language, hence gives immediate results.
4. Used for both scientific and commercial purpose.
5. Uses simple, clear, concise instructions that are easy to read even by non-
programmers, hence easy to maintain, debug, or enhance.
6. Codes are comparatively simpler, shorter, and less verbose (wordy-too many words)
compared to other HLLs likes C++, hence easy to learn because of its simple syntax
and shorter codes.
7. It works on Windows, Linux/Unix, Mac, OSX, and other operating systems, even on
small devices. It runs on microcontrollers, (single-purpose connect, integrated circuit
designed for a specific purpose) used in devices/ appliances, toys, remote control and
embedded devices like washing machine.
8. It can be easily integrated with C++, C, CON, ActiveX, COBRA, JAVA.

DOWNLOADING PYTHON: -
Steps
 Open Google Chrome or Internet Explorer.
 Type https://www.python.org/download/ in the address bar and press enter
 The download page of python appears
Download Python 3.8.0

 The setup of Python starts to download on our computer system in the download folder

INSTALLING PYTHON: -
 Open the download folder of your computer system. Click on the setup of Python that you
download.
 Install Now. Select ‘Install launcher for all users’ option and click on the option ‘Install
now’
 The setup process will start.
 Once the setup is complete, the following message will appear. Click on close.
 We get the message ‘Setup was successful’. Click on ‘close’.

Getting started with Python: -


Python can be started in 2 modes:
1. Python (Command line)/Interactive Mode
2. Python (IDLE)/ Script Mode

1. Python Command Line: -


 Here we can write the command directly as interpreter is used as the translator.
Steps to start Python Command Line: -
Start  ALL APPS  Python 3.8. Python (Command Line).
The given window appears - called the Python Command Line Window or Python
Interactive mode.

The version of Python may differ according to the program that is installed in our computer.
Similarly, the interpreter may be 32 bit or 64 bit, depending upon our computer.
2. Python (IDLE) – Integrated Development and Learning Environment – is the
graphical IDE for Python.
 Also called Script mode of python.
We can edit, run (execute), Browse and debug Python programs from a single
interface, making it easy to write programs.
Steps-
StartAll app Python 2.7  IDLE
Python shell appears, displaying the Python prompt.
Creating Simple Python Programs: -
>>> (Python prompt)
1. Enter a simple expression 3+2i.e.

>>> 3+2 
5
>>> 3*2 
6
Here single statement programs are executed by Python shell
2. Write a program to print, display “Hello, Python”
>>> Print (“Hello, Python”) 
Hello, Python
>>> 5*2*12 
120

Note: Python Shell executes a single statement. To execute multiple statements,


create a python file with extension .PY and write python scripts(multiple
statements).
Working with Script Mode: -
(program mode) in Python
A script is a text file containing statements that comprise a Python program.
Once the script is created, it can be executed many times without being retyped each time.
The Python edit window is used to write Python programs
Steps – To Create
i. File  New File  Type the program code
ii. To Save File  Save  file name and default extension is .py which is automatically
provided.
Under File, select New Window or press Ctrl + N. That will bring up a new window titled,
“Untitled”.

To execute
Run Run module

If the code is written correctly, then the output is shown in the Python shell window.
To close a file
File  Close
To open a file
File  Open  (a dialog box opens) locate the folder type in the name  Open.
Python will open the program in Edit/Script window.
To exit the environment (Python)
File  Exit

3. To display the output as


Learning Python
It is fun
I like to learn Python
Solution. – Type the following in the Edit Window
print (“Learning Python”)
print (“It is fun”)
print (“I like to learn Python”)

Save it
Run it to get the required output

BASICS OF PYTHON PROGRAMMING


1.Python Keyword –
 Keyword(reserved word) cannot be used as variable names, function name or any
other identifier. These are used to define the syntax and structure of the Python
language.
 Keyboards are case sensitive.
 There are 33 keywords in Python.
 All the keywords except True, False and None are in lower case.
 The list is False, None, True, and, assert, break, class, continue, def, del, elif, else,
except, finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass,
raise, return, try, while, with, yield.

Commentsare shown beginning with # (hash)


Eg>>> print (“Hello World”) #This is silly 
Hello World.
>>>
Comments statements are not part of the python command but used for documentation for
anyone reading the code.
Multiline comments are enclosed in triple quotes.
“‘For a long comment
That cannot fit in
One line”’
Note: also use “““______”””

2. Data Types – tell the compiler what kind of value a variable can hold.
The data types are Number, string and list.
(Numbers and string will be discussed in this chapter).
Numbers: When we enter a number, Python will interpret it as a number. We are not
(user) required to declare the data type while entering numbers.
Number
types of numbers.

Integers Data Type Floating Data Type

Integers – are whole numbers that are either positive, zero or negative. They do not carry
fractional or decimal (significant) part. E.g. (-2,0,2)
Program>>>newnum = 10 
>>>print newnum
10
Floating data type – means number with decimal point. E.g. 0.7, 1.2 etc
Program >>>newfloat = 99.5 or 99.0
>>> print newfloat
99.5
String data type–Continuous set of characters in between single quotes or double quotes.
>>>mystring = ‘Hello World!!!’
>>> print (mystring) 
Hello World!!!
>>> mystring1 = “Hello Everyone”
>>> print mystring1
Hello Everyone
When we use double quotes then apostrophe can be included as character
3. Variable and assignment in Python: -
Assignment statement has the form variable name = expression/value
The expression on the RHS is first calculated and then the result is assigned to the variable.
 e.g.
o Name = “India” # string type.
o a = b = c = 5.0 # multiple variables assigned same value in a single statement.
o a, b, c = 1, 5.0, “abc”

i.e. int a = 1
float b = 5.0
str c = “abc”
Note:
1. This execution produces no output. The purpose is to make association between a
variable and its value.
2. Print the output we must print it with print statement or print function
Program >>> = 2+2
>>> print ()
4
Program>>> = 380.5
>>> print ()
380.5
>>> = 2*
>>> print (x)
>>> 380.5
>>> print ()
761
In computer programming  = +1 means add 1 to the present value of  make reassign the
result of . That is increment of  by 1.
Program>>> = 10
>>> = +1
>>> print ()
11
Rules for naming variables.: -
 Variable names can contain a to z, A to Z, 0 to 9 and _ (underscore)
 Variable name should not begin with a digit.
 Variable names are case sensitive. It is recommended to use small letters.
 Keywords/reserve words cannot be used as variable names e.g.: if, else, print, while
etc.
 Variable names can be of any length but cannot include blank spaces.

4. Operators: are symbols used to perform operations on operands. It returns results


that can be used in application. Python supports many kinds of operators.
Arithmetic Operators +, -, *, /.
Comparison Operators – result in Boolean True or False after comparison between 2
operands. E.g. a>b
 = equal to
 != not equal to
 > greater than
 < less than
 >= greater than equal to
 <= less than equal to
Shortcut keys for various tasks
Ctrl + N –To create a New editing window.
Ctrl + S – Save a Python file.
Ctrl + O – Open an existing Python file
Ctrl + P – Print a Python file
F5 – Run a module
F1 – go to help
Ctrl + Q – Exit from Python IDLE
----------------------------------------------------------xxxx-----------------------------------------------------------

You might also like