Week - 1: Brief History of Python

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Python Programming-20CS31P

WEEK -1
 Python is a general purpose, high level programming language.
Brief history of  Python was developed by Guido Van Rossam in 1989 while working at
python National Research Institute at Netherlands.
 But officially Python was made available to public in 1991. The official
Date of Birth for Python is : Feb 20th 1991.
 Python is recommended as first programming language for beginners.
• Simple and easy Python is a simple programming language.
Features to learn When we read Python program, we can feel like
reading English statements.
• Extensive library Python has a rich inbuilt library
• Portable Python can run on a wide variety of hardware
platforms and has the same interface on all
platforms
• Extendable Enable programmers to add to or customize their
tools to be more efficient.
• Databases Python provides interfaces to all major
commercial databases
• GUI Programming Python supports GUI applications that can be
created and ported.
• Freeware and Open We can use Python software without any license
Source and it is freeware.
• Platform Once we write a Python program, it can run on
Independent any platform without rewriting once again
• Interpreted We are not required to compile Python programs
explicitly. Internally Python interpreter will take
care that compilation
1. For developing Desktop Applications
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

A Python distribution is a - CPython


Python software bundle, which - Anaconda
Distributions contains a Python interpreter - ChinesePython
and the Python standard library - ActivePython
- IPython
- WinPython
- JupyterPython

SHESHADRI A V, DEPT OF CSE, GPT CHN Page 1


Python Programming-20CS31P

 Python 1.0  January 1994


Python  Python 2.0  October 16, 2000
Versions  Python 3.0  December 3, 2008
 Python 3.9  October 5th, 2020
 PyCharm
Python IDEs

 Spyder

 PyDev

 Idle

 Wing

 The Python interpreter is a


Python virtual machine, meaning that
Interpreter it is software that emulates a
physical computer.
 When you write Python
program, compiler generates
code objects for the
interpreter to operate on.
Execution of  After writing the code, we Run on IDLE
python need to run the code to • Write the python code and save it.
programs execute and obtain the • To run the program, go to Run > Run
output. On running the Module or simply click F5.
program, we can check
whether the code is written is Run On IDE (PyCharm)
correct and produces the • Create a new python file and save it with some
desired output. name, say “hello.py”.You don‟t need tospecify
the extension as it will pick it automatically.
• After writing the required code in the python
file, we need to run it.
• To run, Click on the Green Play Button at the
top right corner of the IDE. The second way to
run is, Right click and select „Run File in
Python Console‟ option

SHESHADRI A V, DEPT OF CSE, GPT CHN Page 2


Python Programming-20CS31P

• Indentation in Python refers


Indentation to the (spaces and tabs) that
are used at the beginning of a
Statement.
• The statements with the same
indentation belong to the
same group called a suite.
• Indentation is a very
important concept of Python
because without proper
indenting the Python code,
you will end up seeing
IndentationError and the
code will not get compiled.
• Comments are descriptions that help programmers better understand the
Comments intent and functionality of the program.
• They are completely ignored by the Python interpreter.
• Using comments in programs makes our code more understandable.
• It makes the program more readable which helps us remember why certain
blocks of code were written.
Single line comment Multi line comment
A comment in Python starts with the Python multi-line comment is a piece of
hash character, #, and extends to the end text enclosed in a delimiter (""") on each
of the physical line. end of the comment.
Ex : # This is a comment Ex: """ This is a multi
comment line """

Best practices for • Proper Documentation and Commenting and Proper Indentation
python • Proper Naming of Variables, Classes, Functions and Modules
programming • Writing Modular Code
• Use inbuilt functions
• Exception handling
• Avoid Creating Global Variables
Character set • Character set is a valid set of • Alphabets: All capital (A-Z) and small
characters recognized by the (a-z) alphabets.
Python language. • Digits: All digits 0-9.
• These are the characters we • Special Symbols: Python supports all
can use during writing a kind of special symbols like, ” „ l ; : ! ~
Python programs. @#$%^`&*()_+–={}[]\.
• White Spaces: White spaces like tab
space, blank space, newline, and
carriage return.
Tokens A token is the smallest individual Ex: a=20+30 is an instruction. Here a ,
unit in a python program. Tokens = , 20, + and 30 are the tokens
are used to construct an instruction
in a Python program

SHESHADRI A V, DEPT OF CSE, GPT CHN Page 3


Python Programming-20CS31P

Types Of Tokens Identifiers


• Keywords
• Literals
• Operators
• Delimiters
Identifiers • Identifiers are names given to Ex: a= 10
identify Variables, functions, arrays, Here „a‟ is the name of the
class etc.. variable.
Ex: Age=30
Here „Age‟ is the name of the
variable.
Rules to define 1. The only allowed characters in Ex: Cash = 300 √
identifiers in Python identifiers are Ca$h = 300 X
• alphabets(A-Z, a-z)
• digits(0 to 9)
• underscore symbol( _ )
2. Identifiers should not start with digit. Ex: 123total X
total123 √
3. Identifiers are case sensitive Ex: Total and total are different
4. Keywords cannot be used as Ex: def=300 X because def is a
identifiers. keyword.

5. Spaces are not allowed in identifiers Ex: total amount = 1000 X


total_amount = 1000 √

Keywords • These are the words that are already Ex: True, None, False, if, else, while
reserved for some particular purposes. etc…
• They are also called as reserved words.
• Keywords cannot be used as identifiers.
• >>> keyword.kwlist
Literals • Literals refer to the values stored in a Ex: a=20 Here 20 is refered as literal
variable. (numeric)
• Ex: name=“Rossom” Here „Rossom‟
is refered as literal (string).
Operators • Operators are the symbols that perform a Ex: +, - , * , /, %, < ,>, =, !=, ==, >=, <=
specific operation on given values and etc
give a result. Ex: a=10+20 In this example, + is called
an operator and 10 and 20 are called
operands
Delimiters • Delimiters refer to the symbols that Ex: comma (,) semicolon ( ;) colon( :)
separate two text strings. period ( .) braces {} slash ( / \) etc
Variables • Variables are containers for storing data
values. Example: x = 5
• A variable is created the moment you y = "John"
first assign a value to it. print(x) >>> 5
print(y) >>> John

SHESHADRI A V, DEPT OF CSE, GPT CHN Page 4


Python Programming-20CS31P

Naming • A variable can have a short name (like x and y) or a more descriptive name (age,
rules for carname, total_volume).
variables • A variable name must start with a letter or the underscore character
• A variable name cannot start with a digit
• A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three different variables).

Assign Value • Assignment sets a value to a variable. Ex: myFirstVariable = 1


To Variables • To assign variable a value, use the equals mySecondVariable = 2
sign (=) myFirstVariable = "Hello You"

SHESHADRI A V, DEPT OF CSE, GPT CHN Page 5

You might also like