1.1-Basics of Python Pog
1.1-Basics of Python Pog
HYDERABAD REGION
Output :-
Computer Science and Informatics Practices
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators/Delimiters
Keywords
Reserve word of the compiler/interpreter which can’t be
used as identifier.
Identifiers
A Python identifier is a name used to identify a variable,
function, class, module or other object.
* An identifier starts with a letter A to Z or a to z or an
underscore (_) followed by zero or more letters,
underscores and digits (0 to 9).
* Python does not allow special characters
* Identifier must not be a keyword of Python.
* Python is a case sensitive programming language.
Thus, Rollnumber and rollnumber are two different
identifiers in Python.
Some valid identifiers : Mybook, file123, z2td, date_2, _no
Some invalid identifiers: 9show,my.book,fname-lname
Literals
Literals in Python can be defined as number, text, or other
data that represent values to be stored in variables.
Hello
Hello
Operators
Operators can be defined as symbols that are used
to perform operations on operands.
Types of Operators
1. Arithmetic Operators.
2. Relational Operators.
3. Assignment Operators.
4. Logical Operators.
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Operators
Operators can be defined as symbols that are used
toperform operations on operands.
Types of Operators
1. Arithmetic Operators.
2. Relational Operators/Comparison Operator
Relational Operators are used to compare the
values.
3. Augmented Assignment Operators
Used to assign values to the variables.
4. Logical Operators
Logical Operators are used to perform logical
operations on the given two variables or values.
a=30
b=20
if(a==30 and b==20):
print('hello')
output- hello
5. Bitwise Operators
2’s complement of 5
6. Membership Operators
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
Operators Precedence
Highest precedence to lowest precedence table. Precedence is used
to decide ,which operator to be taken first for evaluation when two
or more operators comes in an expression
Punctuators/Delimiters
Used to implement the grammatical and
structure of a Syntax. Following are the python
punctuators.
Barebone of a python program
Variables
Variable is a name given to a memory location. A
variable can consider as a container which holds value.
Python is a type infer language that means you don't need to
specify the datatype of variable. Python automatically get
variable datatype depending upon the value assigned to the
variable.
Variables
Concept of L Value and R Value in variable
Lvalue and Rvalue refer to the left and right side of
the assignment operator. The Lvalue (pronounced: L
value)concept refers to the requirement that the operand on
the left side of the assignment operator is modifiable,
usually a variable. Rvalue concept fetches the value of the
expression or operand on the right side of the
assignment operator.
example: amount = 390
The value 390 is pulled or fetched (Rvalue) and stored into
the variable named amount (Lvalue); destroying the
value previously stored in that variable.
Dynamic typing
Constants
A constant is a type of variable whose value cannot be changed. It is
helpful to think of constants as containers that hold information which
cannot be changed later. In Python, constants are usually declared and
assigned in a module. Here, the module is a new file containing
variables, functions, etc which is imported to the main file. Inside
the module, constants are written in all capital letters and underscores
separating the words.
Input and Output
print() Function In Python is used to print output on the screen.
Syntax of Print Function - print(expression/variable)
e.g.
print(122)
Output :-
122 print('hello India') Output :-
hello India
print(‘Computer',‘Science')
print(‘Computer',‘Science',sep=' & ')
print(‘Computer',‘Science',sep=' & ',end='.')