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

PYTHON

Uploaded by

Purushottam
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)
16 views5 pages

PYTHON

Uploaded by

Purushottam
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/ 5

Python Keywords and Identifiers

Keywords – Keywords are reserved words in Python that the Python interpreter
uses to recognize the program’s structure. In Python, keywords are predefined
words with specific meanings.
Example of Keywords –

False, class, finally, is, return, None, continue, for lambda, try, True, def, from,
nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import,
pass, break, except, in, raise etc.

Identifiers – An identifier is a name given to a variable, function, class, module,


or other object. The identification is made up of a series of digits and
underscores.
1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase
(A to Z) or digits (0 to 9) or an underscore _.
2. An identifier cannot start with a digit
3. Keywords cannot be used as identifiers
4. We cannot use special symbols like !, @, #, $, % etc. in our identifier
5. Identifier can be of any length
6. Python is a case-sensitive language.
Example of Identifier
var1
_var1
_1_var
var_1
Variables, Constants and Data Types
Variables

A variable is a memory location where you store a value in a programming


language. In Python, a variable is formed when a value is assigned to it.
Declaring a variable in Python does not require any further commands.

There are a certain rules and regulations we have to follow while writing a
variable

1. A number cannot be used as the first character in the variable name. Only
a character or an underscore can be used as the first character.
2. Python variables are case sensitive.
3. Only alpha-numeric characters and underscores are allowed.
4. There are no special characters permitted.
Constants

A constant is a kind of variable that has a fixed value. Constants are like
containers that carry information that cannot be modified later.

Datatype

In Python, each value has a datatype. Data types are basically classes, and
variables are instances (objects) of these classes, because everything in Python
programming is an object.

Python has a number of different data types. The following are some of the
important datatypes.

1. Numbers
2. Sequences
3. Sets
4. Maps
a. Number Datatype

Numerical Values are stored in the Number data type. There are four categories
of number datatype –

1. Int – Int datatype is used to store the whole number values. Example :
x=500
2. Float – Float datatype is used to store decimal number values. Example :
x=50.5
3. Complex – Complex numbers are used to store imaginary values.
Imaginary values are denoted with ‘j’ at the end of the number. Example :
x=10 + 4j
4. Boolean – Boolean is used to check whether the condition is True or
False. Example : x = 15 > 6 type(x)
b. Sequence Datatype

A sequence is a collection of elements that are ordered and indexed by positive


integers. It’s made up of both mutable and immutable data types. In Python,
there are three types of sequence data types:

1. String – Unicode character values are represented by strings in Python.


Because Python does not have a character data type, a single character is
also treated as a string. Single quotes (‘ ‘) or double quotes (” “) are used
to enclose strings. These single quotes and double quotes merely inform
the computer that the beginning of the string and end of the string. They
can contain any character or symbol, including space. Example : name =
”Rakesh kumar”
2. List – A list is a sequence of any form of value. The term “element” or
“item” refers to a group of values. These elements are indexed in the same
way as an array is. List is enclosed in square brackets. Example : dob =
[19,”January”,1995]
3. Tuples – A tuple is an immutable or unchanging collection. It is arranged
in a logical manner, and the values can be accessed by utilizing the index
values. A tuple can also have duplicate values. Tuples are enclosed in
(). Example : newtuple = (15,20,20,40,60,70)
c. Sets Datatype

A set is a collection of unordered data and does not have any indexes. In Python,
we use curly brackets to declare a set. Set does not have any duplicate values.
To declare a set in python we use the curly brackets.

Example : newset = {10, 20, 30}

d. Mapping

This is an unordered data type. Mappings include dictionaries.

Dictionaries

In Python, Dictionaries are used generally when we have a huge amount of data.
A dictionary is just like any other collection array.

Operators
Operators are symbolic representations of computation. They are used with
operands, which can be either values or variables. On different data types, the
same operators can act differently. When operators are used on operands,
they generate an expression.

Operators are categorized as –

 Arithmetic operators
 Assignment operators
 Comparison operators
Logical operators

 Identity operators
 Membership operators
 Bitwise operators
Arithmetic Operators

Mathematical operations such as addition, subtraction, multiplication, and


division are performed using arithmetic operators.

Operator Meaning Expression Result

+ Addition 20 + 20 40

– Subtraction 30 – 10 20

* Multiplication 10 * 100 1000

/ Division 30 / 10 3

// Integer Division 25 // 10 2

% Remainder 25 % 10 5

** Raised to power 3 ** 2 9

Assignment Operator

When assigning values to variables, assignment operators are used.

Operator Expression Equivalent to

= x=10 x = 10

+= x += 10 x = x + 10

-= x -= 10 x = x – 10

*= x *= 10 x = x * 10

 /=  x /= 10  x = x / 10

Comparison Operator

The values are compared using comparison operators or relational operators.


Depending on the criteria, it returns True or False.

Operator Meaning Expression Result

> Greater Than 20 > 10 True

20 < 50 False
< Less Than 20 < 10 False

10 < 40 True

== Equal To 5 == 5 True

5 == 6 False

!= Not Equal to 67 != 45 True

35 != 35 False

Logical Operator

Logical operators are used to combine the two or more then two conditional
statements –

Operator Meaning Expression Result

And And Operator True and True True

True and False False

Or Or Operator True or False True

False or False False

Not Not Operator Not False True

Not True False

You might also like