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

Indentifiers

The document outlines the rules for creating identifiers in Python, including naming conventions and case sensitivity. It distinguishes between statements and expressions, explaining their functions and providing examples. Additionally, it covers variable storage, operator precedence, associativity, indentation, comments, and numeric data types.

Uploaded by

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

Indentifiers

The document outlines the rules for creating identifiers in Python, including naming conventions and case sensitivity. It distinguishes between statements and expressions, explaining their functions and providing examples. Additionally, it covers variable storage, operator precedence, associativity, indentation, comments, and numeric data types.

Uploaded by

Omkar Gurav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Identifiers - An identifier is a name used to identify a variable, function,

class, or object in Python.

Rules for Identifiers

1) Must start with a letter (a–z, A–Z) or underscore (_)


2) Cannot start with a number
3) Can contain letters, numbers, and underscore
4) No spaces allowed
5) Keywords cannot be used as identifiers
6) Python identifiers are case-sensitive

EXAMPLE –

Name = “Sakshi” # name is an identifier

_Age = 20 # age is an identifier

VALID INDETIFIERS-

student_name

_age

totalMarks

Python123

INVALID INDETIFIERS-

1name # starts with number

total-marks # hyphen not allowed

class # keyword

student name # space not allowed

CASE SENSITIVITY –

A = 10

A = 20

Print(a) # 10

Print(A) # 20

KEYWORDS-

Keywords are predefined words in Python that are used to perform


specific actions in a program.
EXPRESSIONS AND STATEMENTS-

A statement is an instruction that Python executes to perform an


action.

Types of Statements

 Assignment statement
 Conditional statements (if, else, elif)
 Looping statements (for, while)
 Control statements (break, continue, pass)
 Function statement (def)
 Import statement (import)

EXAMPLE -

X = 10 # assignment statement

Print(x) # print statement

If x > 5: # if statement

Print(“Big”)

EXPRESSIONS IN PYTHON -

An expression is a combination of values, variables, and operators that


produces a result.

Expressions return a value.

EXAMPLE –

10 + 5 # arithmetic expression

X>3 # relational expression

A and b # logical expression

“Py” + “thon” # string expression

Difference Between Statement and Expression -

Statement Expression

Performs an action. Produces a value

May not return value. Always returns value

Example: print(x) Example: x + 2

VARIABLE –

A variable stores data in memory.


Example:

Age = 20

Name = “Sakshi”

Python is dynamically typed (no need to declare data type).

EXAMPLE-

X = 10

Name = “Sakshi”

Price = 99.50

a, b, c = 1, 2, 3

PRECEDENCE -

Operator precedence decides which operator is evaluated first in an


expression.

When more than one operator appears in an expression, higher-


precedence operators are evaluated first.

EXAMPLE –

Result = 10 + 5 * 2

Print(result)

According to precedence rules:

5 * 2 = 10 ← multiplication first

10 + 10 = 20 ← then addition

If you want addition first

Use parentheses:

Result = (10 + 5) * 2

Print(result)

ASSOCIATIVITY -

Associativity tells us the direction in which operators of the same


precedence are evaluated.

*Left-to-right

Result = 10 – 5 – 2

Print(result)
*Right-to-left

a = b = c = 10

Indentation-

Python uses indentation instead of braces {}.

EXAMPLE –

If 10 > 5:

Print(“Correct”)

Print(“Python”)

ERROR –

If 10 > 5:

Print(“Wrong”) # IndentationError

Comments in Python-

Comments are used to explain code.

Single-line Comment:

# This is a comment

Multi-line Comment:

“””

This is

Multi-line

Comment

“””

DATA TYPES -

A data type tells Python what kind of value a variable is storing.

Numeric Data Types:-

Used to store numbers.

a) Integer (int)

Whole numbers (positive or negative)

A = 10

B = -25
print(a, b)

b) Float (float)

Numbers with decimal point

X = 3.14

Y = 10.5

print(x,y)

You might also like