0% found this document useful (0 votes)
3 views3 pages

Variable, Literal & Operators

The document provides an overview of Python programming concepts, including comments, variables, literals, keywords, and operators. It explains single and multi-line comments, the definition and rules of variables, types of literals (string, numeric, boolean, and special), and the significance of keywords. Additionally, it categorizes operators into arithmetic, assignment, and relational types, with examples for each category.

Uploaded by

skgjhvkgvjh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Variable, Literal & Operators

The document provides an overview of Python programming concepts, including comments, variables, literals, keywords, and operators. It explains single and multi-line comments, the definition and rules of variables, types of literals (string, numeric, boolean, and special), and the significance of keywords. Additionally, it categorizes operators into arithmetic, assignment, and relational types, with examples for each category.

Uploaded by

skgjhvkgvjh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

NIELIT GORAKHPUR

Course Name: Python Programming

Comments in Python
 Single Line Comments
To write a single line comment in use # symbol.
Ex : # this is the comment

 Multi Line Comments


Triple double quotes (“”””) or triple single quotes (‘’’) are called multi line
comments or block comments
Ex : “”” this is the multi line
comments”””

What is Variable?
 A variable is a name which is used to refer memory location and used to hold value.
 In Python variable is also called as an identifier.

Rules of Python variables:


 A variable name must start with a letter or the underscore character.
 A variable name cannot start with a number.
 A variable name can only contain alpha-numeric characters and underscores (A-z,0-9, and _)
 Variable names are case sensitive.
Example:
x=10
y=20

What is Literal?
 Literals can be defined as a data that is given in a variable or constant.
 Python Support the following literals:

String Literals
String literals can be formed by enclosing a text in the quotes. We can use both single as well as double
quotes for a string. A string literal can also span multiple lines.

Numeric Literals
Numbers stores numeric values. Python create number objects when a number is assigned to a var
variable.
Numeric literals can belong to following four different numerical types.
 int (Singed integer)
 float (Float is used to store floating point numbers)
 complex (Complex number)

Page 1 of 3
Boolean Literals
A Boolean literal can have any of the two value: True or False

Special Literals
Python contain one special literal None. It is used to specify to that field that is not created.

Keywords
 Python keywords are special reserved words which convey a special meaning to the
compiler/interpreter.
 Each keyword has a special meaning and a specific operation.
 Keywords cannot be used as a variable.

List of Python Keywords

False await else import pass

None break except in Raise


True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield

Operator & Operand


• Operators are special symbols which represents computation.
• They are applied on operand(s), which can be values or variables. Operators when applied on
operands form an expression.
• Operators are categorized as Arithmetic, Assignment, Relational, Logical, Special and Bitwise.
• Value and variables when used with operator are known as operands.

Mathematical/Arithmetic Operators
• Arithmetic operators are used to perform mathematical operations like addition, subtraction,
multiplication and division.
Assume a=5 and b=3

Operator Meaning Example Output


+ Addition Operator a+b 8
- Subtraction Operator a-b 2
* Multiplication Operator a*b 15
/ Division Operator a/b 1.666
% Modulus Operator a%b 2
* Exponent Operator a**b 125
*
/ Floor Division a//b 1
/

Page 2 of 3
Assignment Operators
• These operator are useful to store the right side value into a left side variable
• Assume a=20, y=10 and z=5

Operator Meaning Example Result


= Assignment Operator
+ Addition Assignment Operator z+=x z=25
=
- Subtraction Assignment Operator z-=x z=-15
=
* Multiplication Assignment Operator z*=x z=100
=
/ Division Assignment Operator z/=x z=0.25
=
% Modulus Assignment Operator z%=x z=5
=
**= Exponentiation Assignment Operator z**=y z=9765625

Relational Operators
• Relational operators compares the values.
• It either returns True or False according to the condition.

Page 3 of 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy