0% found this document useful (0 votes)
12 views5 pages

Basic of python class 11

The document provides an overview of Python programming, including its definition, features, and modes of execution. It covers the basics of Python syntax, character sets, tokens, identifiers, literals, operators, and expressions. Additionally, it explains the historical context of Python's development and its dynamic typing nature.

Uploaded by

pallathika2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
12 views5 pages

Basic of python class 11

The document provides an overview of Python programming, including its definition, features, and modes of execution. It covers the basics of Python syntax, character sets, tokens, identifiers, literals, operators, and expressions. Additionally, it explains the historical context of Python's development and its dynamic typing nature.

Uploaded by

pallathika2
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

BASIC OF PYTHON

What is programming?
An ordered set of instructions to be executed by a computer to carry out a specific task is called a program, and the
language used to specify this set of instructions to the computer is called a programming language.
What is python?
Python is a general purpose, high level, dynamic, interpreted programming language and it supports oops concepts to
develop an applications.
Modes of execution:
There are two modes for using the Python interpreter:
1. Interactive Mode :
In interactive mode (python.exe/py.exe), the result is returned immediately after pressing the enter
key.
2. Script Mode:
In script mode (IDLE), a file must be created and saved before executing the code to get results.
History:
The implementation of Python was started in December 1989 by Guido Van Rossum at CWI in Netherland.In February
1991, Guido Van Rossum published the code (labeled version 0.9.0)

FEATURES OF PYTHON
 Easy-to-Learn: Python has few keywords, simple structure, and a clearly defined syntax. This allows the student
to pick up the language quickly.
 Easy-to-read: Python code is more clearly defined and visible to eyes.
 Easy-to-maintain: Python’s source code is fairly easy-to-maintain.
 A broad standard library: Python’s bulk of the library is very portable andcross-platform compatible on UNIX,
and Windows.
 Interactive Mode: Python has support for an interactive mode which allows interactive testing and debugging of
code.
 Portable: Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
 Extendable: You can add low-level modules to the Python interpreter. These modules 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 to many system calls,
libraries, and windows system, such as windows MFC, Macintosh, and the X Window system of UNIX.
 Scalable: Python provides a better structure and support for large programs than shell scripting.
 Dynamically Typed: We need to specify the data type of variable while creation. Python can understand the data
type of variable after storing the value. It is called dynamically typed.
Working with Python Python Code Execution:
Python’s traditional runtime execution model:
Source code you type is translated to byte code, which is then run by the Python Virtual Machine (PVM). Your
code is automatically compiled, but then it is interpreted.

1
PYTHON CHARACTER SET:

A set of valid characters recognized by python. Python uses the traditional ASCII character set. The latest version
recognizes the Unicode character set. The ASCII character set is a subset of the Unicode character set.
Letters: – A-Z,a-z
Digits: – 0-9 Special
Symbols: – Special symbol available over keyboard
White spaces: – blank space, tab, carriage return, new line, form feed
Other characters: - Unicode

TOKEN: Smallest individual unit in a program is known as token.


1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators/Delimiters
1. Keywords:
 Keywords are predefined; reserved words used in programming that have special meanings to the
compiler.
 Keywords are part of the syntax and they cannot be used as an identifier.
 All the keywords except True, False and None are in lowercase.

2
2. Identifiers:
A Python identifier is a name used to identify a variable, function, class, module or other object.
Naming rules for identifier
DO e.g. (valid) DON’T e.g. (invalid)

Can be used A to Z A=10 Keywords can’t be used as identifier None=10

Can be used a to z a=’hi’ Identifier should not start with digit(0 to 9) 9a=10

Can be used 0 to 9 Ab99=150.55 Space is not allowed between words My value=555

Can underscore (__) My_value=5 Special characters can’t be used A#@=’hello’

Any Length

 Starting an identifier with a single leading underscore indicates that the identifier is private.
 Starting an identifier with two leading underscores indicates a strong private identifier.
 If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
3. Literals
Literals in Python can be defined as number, text, or other data that represent values to be stored in variables.
Types:

Integer String float special hex octa Binary complex


Age=20 Person=”Ram” Marks=75.5 Word=None E=0Xa t=0o7 v=0b101 c=4+5j
Id_no=11 Course=”computer” Price=10.50 e=0xA d=4+5J

Literal collections
Literals collections in python includes list, tuple, dictionary, and sets.
E=[10,20,30]
Escape sequence:
The backslash “\” is a special character, also called the “escape” character.
It is used in representing certain whitespace characters:

1. \' Single Quote


2. \’’ Double quote
2. \\ Backslash
3. \n New Line
4. \r Carriage Return
5. \t Tab
6. \b Backspace
7. \f Form Feed
8. \ooo Octal value
9. \xhh Hex value
10. \v Vertical tab

3
4. Operators:
Operators can be defined as symbols that are used to perform operations on operands.
Types of Operators

Operator Symbols Example


1. Arithmetic +, - ,* , %, /, //, ** print(10/2) print(10//2) print(10%2)
output: 5.0 output: 5 output: 0
2. Relational <, >, >=, <=, ==, != print(10> 20) print(10==10) print(“hello”<”Hello”)
output: False output: True output: True
3. Assignment =, +=, *=, /=, //+, a=50 a+=a a/=b
b=10 print(a) print(a)
output: 100 output: 5.0
4. Logical and, or, not 50>10 and 1<4 10<5 or 5==6 print( not 5)
output: True output: False output: False
5. Bitwise &, | , ~,<<,>> print(10 & 15) print(25 | 10) print( ~32)
output: 10 output: 27 output: -33
6. Membership in , not in List=[10,30,50,70] name=”Sai Priya” name=”Sai Priya”
print( 50 in List) print(“P” in name) print(“p” in name)
output: True output: True output: False
7. Identity is , is not a=10 print( id(a) ) print( a is b)
output: 1616 output: True
b=5 print(id(b))
output: 1456 note:
a=b print(id(b)) a and b are pointing
output: 1456 same address.

Operator explanation
1. Arithmetic Arithmetic Operators are used to perform arithmetic operations like addition,
multiplication, division etc.
2. Relational Relational Operators are used to compare the values.
3. Assignment Used to assign values to the variables.
4. Logical Logical Operators are used to perform logical operations on the given two
variables or values.
5. Bitwise Bitwise operators are used to perform bitwise calculations on integers. The
integers are converted into binary format and then operations are performed bit
by bit.
6. Membership The membership operators in Python are used to validate whether a value is
found within a sequence such as such as strings, lists, or tuples.
7. Identity Identity operators in Python compare the memory locations of two objects.

Expression output Expression output


10/5 2.0 10.0//7 1.0
10/3 3.3333333333333335 10.14//7 1.0
10//5 2 10.0%5 0.0
10//7 1 5%10 5
0//5 0 5%5 0
10%5 0

4
Precedence: The order in which the operators will be evolved in an expression.
Associativity: The order in which the operators of the same precedence will be evaluated in an expression.
Precedence operator associatively examples
1 ( ) Left- Right (5+8)*3–6/2
2 ** Right-Left 14 + 13 % 15
3 *, /, //, % Left- Right ( 5 + 8 ) * 3 – 12/ 2
4 +,_ Left- Right 15.0 / 4 + (8 + 3.0
5 not x Right to left not 10> 5 and 2 < 11 or not 10 < 2
6 and Left to right
7 or Left to right

logical operator
evaluates to either True or False based on the logical operands on either side.
Every value is logically either True or False.
By default, all values are True
except None, False, 0 (zero), empty collections "", (), [], {}, and few other special values.
x or y if x is true, then x, else y 10 or 5 10
0 or 5 5
x and y if x is false, then x, else y 10 and 5 5
0 and 10 0
not x if x is false, then True, else False not 10 False

5. Punctuators/Delimiters
These are the symbols that used in Python to organize the structures, statements, and expressions.
Used to implement the grammatical and structure of a Syntax
, . ‘ “ \ [] { } ( ) @ -= += *= //= **== = << >>

You might also like