1-42 getting started with python online
1-42 getting started with python online
Python
Who uses Python
• Red Hat :uses python for configuring and managing Linux operating system
• Infoseek: uses Python within certain parts of its public search engines
• NASA: takes advantage of strong numerical abilities of Python and for
plotting the paths taken by satellites.
• Industrial Light and Magic (ilm.com): famous for doing the special effects
on films such as Star Wars, Star Trek and Indiana Jones uses Python to
produce commercial grade animation. In fact, if you visit their website, you’ll
see they have a number of vacancies for Python Programmers.
Points to remember
• Python Programming language was developed by Guido Van Rossum in
February 1991 at National research institute for mathematics, Netherlands.
• Python is presently owned by PSF(Python Software Foundation).
• It is influenced by two programming languages:
• ABC language which was replacement of BASIC
• Modula-3
• It is Object Oriented Programming language
Points to remember
• It is high level programming language, which means that it separates the
user from the underlying operating system as much as possible. However,
unlike other languages, python provides you with the ability to access the
operating system at a lower level if you desire.
• Python was named after famous BBC comedy show Monty Python’s Flying
Circus.
• Python is a case sensitive language.
Advantages of Python
• It is easy to learn and use as it is programmer friendly.
• Expressive language: Compact and easier to understand.
• Python follows “batteries included” philosophy because of its standard libraries and
packages for diverse functionality such as e-mail, web pages, databases, GUI development,
network connections, scientific and non scientific applications and many more.
• Portable language: it can run on variety of platforms(windows /linux /unix /mac
/supercomputers / smart phones). Python is supplied with a module to the toolkit Tk
interface libraries and it’s possible to write an application on one platform and use it on
other platforms without making any modifications.
Advantages of Python
• Interpreted language: Python interpreter interprets and executes the code line by line and
hence is easy to debug language. Although python is considered as an interpreted language,
it employs a compilation stage that translates the raw text python script into a series of
bytecodes, which are then executed by the Python Virtual Machine(PVM). The use of the
compilation and bytecode stages helps to improve performance and makes python much
faster than pure interpreters such as BASIC, but slower than the truly compiled languages
such as C and PASCAL. However, unlike many other languages, the bytecode versions of
modules can be saved and executed without having to recompile them each time they are
required, thereby improving performance by eliminating the compilation stage. Note that
the bytecode that is created is completely platform and operating system independent.
Advantages of Python
• Free and open source: it is freely available and it can be improved or extended. It means that
you can write python programs without having to purchase any software and without having
to worry about licensing issues. You can even download the source code to the python
software if you want to take a closer look at how the python language works.
• Python supports an extension called NumPy, which provides interfaces to many standard
mathematics libraries. The python language also supports unlimited precision. If you want to
add two 100 digit numbers together, you can do so with Python without requiring a third
party extension. If you need real speed in mathematical applications, the NumPy extension
written in C, operates faster than the native math supported by Python.
Advantages of Python
• Supports text processing: Python can split, separate, summarize and report on any data.
• Supports RAD (Rapid Application Development). Python is so straightforward to develop
applications with. The extensive module library that comes with Python provides direct
interfaces to many of the protocols, tools, and libraries that you would otherwise have to
develop yourself.
• Python also supports XML and HTML so that you can parse user input and produce top
quality formatted output via a web server.
Disadvantages of Python
• Not the fastest language: though python offers faster development but execution
times are not that fast as that of compiled languages.
• Lesser libraries than C, Java, Pearl
• Not strong on type binding. Shows type mismatch issues.
• Program written in python is not easily convertible to other language.
PROGRAM AND PROGRAMMING LANGUAGE
Comment entry
• Preceded with #
Program 5-2 Write a program to display values of
• Not executed by
interpreter variables in Python.
#Program 5-2
• Single line • Variable
#To display values of variables
comment entry • Identify the other variable
message = "Keep Smiling"
• Wherever a variable name
print(message)
occurs in an expression,
userNo = 101
the interpreter replaces it
print('User Number is', userNo)
with the value of that
Output: particular variable.
• print() function is Keep Smiling
to display on to User Number is 101
monitor
• Anything which
appears in single
quotes ‘ ’ or double • Note the space
quotes “ ” appears appeared in output by
as a string itself
(sequence of
characters)
INTERACTIVE/SCRIPT MODE
TOKENS
IDENTIFIERS
KEYWORDS LITERALS OPERATORS PUNCTUATORS
(NAMES)
INTERACTIVE/SCRIPT MODE
print(result)
OPERATOR
Output:
30 PUNCTUATOR
PYTHON KEYWORDS
2. Name the identifier for storing the average of the marks obtained earlier.
TASK: Which of the following identifier names are invalid and why?
i) Serial_no.
ii) 1st_Room
iii) _Percentage
iv) Total_Marks
v) Total Marks
vi) Hundred$
vii) total-Marks
viii) True
PYTHON IDENTIFIERS
identifiers are names used to identify a variable, function, or other entities in a program.
TASK: Which of the following identifier names are invalid and why?
i) Serial_no. [invalid (.)]
ii) 1st_Room [can’t begin with digit]
iii) _Percentage [valid]
iv) Total_Marks [valid]
v) Total Marks [can’t have space]
vi) Hundred$ [can’t have any special character other than _]
vii) total-Marks [can’t have any special character other than _]
viii) True [invalid as it’s a keyword]
PYTHON LITERALS/VALUES (CONSTANT)
Data items that have a fixed value
LITERALS
STRING LITERAL: It is a sequence of characters surrounded by quotes (single or double or triple quotes)
EXAMPLES:
‘A’ ‘a’
“a” “abc”
‘abc’ “amy’s”
‘amy”s’ ‘1-x-0-w-o-25’
“112fbD29” “123”
“!@#$%^”
‘123’
PYTHON LITERALS/VALUES (CONSTANT)
Data items that have a fixed value
STRING LITERAL: It is a sequence of characters surrounded by quotes (single or double or triple quotes)
STRING LITERAL: It is a sequence of characters surrounded by quotes (single or double or triple quotes)
STRING LITERAL: It is a sequence of characters surrounded by quotes (single or double or triple quotes)
STRING TYPES
ADDING \(BACKSLASH)
AT THE END OF SINGLE
LINE STRING
STRING LITERAL: It is a sequence of characters surrounded by quotes (single or double or triple quotes)
SINGLE LINE STRINGS: The strings that you create by enclosing text in single quotes or double quotes. In other words,
they must terminate in one line
PYTHON LITERALS/VALUES (CONSTANT)
Data items that have a fixed value
MULTI LINE STRINGS: These strings allow you to store text spread across multiple lines as one single string
Enter pressed(called
EOL character) is
also counted here
EOL character is
NOT counted here
PYTHON LITERALS/VALUES (CONSTANT)
Data items that have a fixed value
NUMERIC
LITERALS