0% found this document useful (0 votes)
4 views4 pages

Python Fundamentals Notes-Tokens

The document provides notes on Python tokens, including keywords, identifiers, operators, and literals. It outlines the rules for naming variables, valid and invalid examples, and details various types of operators such as arithmetic, relational, assignment, and logical operators. Additionally, it explains different types of literals in Python, including string, integer, floating-point, Boolean, and None literals.

Uploaded by

anugrahlohith
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)
4 views4 pages

Python Fundamentals Notes-Tokens

The document provides notes on Python tokens, including keywords, identifiers, operators, and literals. It outlines the rules for naming variables, valid and invalid examples, and details various types of operators such as arithmetic, relational, assignment, and logical operators. Additionally, it explains different types of literals in Python, including string, integer, floating-point, Boolean, and None literals.

Uploaded by

anugrahlohith
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

SHARJAH INDIAN SCHOOL, JUWAIZA

GRADE 9 WORK EDUCATION NOTES

Python Tokens
The Smallest individual units in Python programs are known as Tokens.

Python has mainly 5 types of tokens which are given below -:


1. Keywords
2. Identifiers
3. Operators
4. Literals
5. Punctuators

Keywords- Keywords are the reserved words having special meaning and purpose in Python.
Eg:- true, false, if, and, break.

Identifiers- An identifier is a name given to a variable. It helps to differentiate one entity from
others.

Python Variable Name Rules


• A variable name must start with an alphabet (capital or small) or an underscore
character
• A variable name cannot contain spaces.
• A variable name can contain any number of letters, digits, and underscore.
• A Python keyword cannot be used as a variable name.
• Special characters aren’t allowed in variable names except for underscores.

Which of the following variable names are valid/invalid?

(a)123 Hello-Invalid

(b) Sum- Valid


(c) abc@123 - Invalid
(d) 2myvar - Invalid
(e)my-var - Invalid

(f) MYVAR- Valid

(g)_name – Valid
OPERATORS
An operator is a symbol or letter which causes the compiler to take any action and yield a value.
An operator acts on different data items called operands.
The various operators are
1. Arithmetic Operators
2. Relational Operators
3. Assignment Operators
4. Logical Operators
5. Membership Operators
6. Identity Operators

1. Arithmetic

Operator Meaning Example


+ Addition 2+5=7
- Subtraction 10-2=8`
* Multiplication 2*3=6
/ Division 10/2=5
// Floor division [Divide and round the result 5 // 2 = 2
down to the nearest whole number]
% Return remainder after division 9%2=1
** Exponent 4**2=16

2. Relational
The relational operators are also known as comparison operators, their main function is to return
either a true or false based on the value of operands.

Operator Description Syntax


Greater than: True if the left operand is
> greater than the right x>y
Less than: True if the left operand is less
< than the right x<y

== Equal to: True if both operands are equal x == y

!= Not equal to: True if operands are not equal x != y


Greater than or equal to True if the left
>= operand is greater than or equal to the right x >= y
Less than or equal to True if the left
<= operand is less than or equal to the right x <= y

3. Assignment operator
Assignment operators are used for assigning the value of the right operand to the left operand. = is
the most used assignment operator in Python.
Eg: a=10

4. Logical operator
Logical operators are used to combine conditional (Boolean) statements. They return True or False
based on the logic.
Operator Description Example Result
and Returns True if both conditions are true 5 > 2 and 10 > 5 True
Returns True if at least one condition is
or 5 > 10 or 10 > 5 True
true
Reverses the result: True becomes False, and
not not(5 > 2) False
vice versa

Literals

Literals in Python are defined as the raw data assigned to variables or constants while
programming.

Various types are string literals, numeric literals, Boolean literals, Floating points, and a special
literal None

String Literals

It is a sequence of characters surrounded by quotes (single, double, or triple).

Eg:- “Aman” , ‘12345’

A character literal is a single character surrounded by a single or double quote

Eg:- ‘a’ , ‘2’

Integer literals

Integer literals are numbers that do not have a decimal point or an exponential part.

Eg: 12 , 25, 100

Floating-point literal

A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part.
You can represent floating point literals either in decimal form or exponential form.

Eg. (Decimal form)- 20.5, 36.8

Eg. (Exponential form) – 2.5E5, 23E9

Boolean literal

Python literal Boolean has two values. One is True, and another one is False.

>>>6<10

>>>True
>>>20>=40

>>>False

None literal

The 'None' literal is used to indicate something that has not yet been created. It is also used to
indicate the end of lists in Python.

>>> v=None

>>>print(v)

>>>None

You might also like