Python is a user-friendly programming language known for its simplicity and readability. It's widely used
in various fields like web development, data science, and automation. With a clear syntax and extensive
libraries, Python makes coding easier and faster.
2. Identifiers in python: -
An identifier is a name given to entities like variables, functions, classes, modules, etc.
1. Must begin with a letter (a-z, A-Z) or an underscore (_).
2. Can be followed by letters, underscores, or digits (0-9).
3. Names are case-sensitive (e.g., "myVar" and "myvar" are different).
4. Cannot be a reserved word or keyword used in Python (such as "if", "for", "while", "def", etc.)
5. Can be of any length.
6. Does not allow punctuation characters
7. Should maintain the standard procedure of naming convention , i.e. …starting class names
with uppercase letters , and other things with small
3. Keywords:-
Keywords in Python are reserved words that have special meanings and are part of the language syntax.
These keywords cannot be used as identifiers (such as variable names, function names, or class names)
because they are used by Python to define the structure and logic of the code.
Attempting to use a keyword as an identifier will result in a syntax error.
Import keyword
Print (keyword.kwlist)
4. Datatypes :-
Python have 3 types of datatypes :
i. Basic Data Types: These are fundamental data types provided by Python. They include:
int: Integer numbers
float: Floating-point numbers
str: Strings
bool: Boolean values - True or False (First letter to be capital always)
complex: Complex numbers
ii. Container Data Types: These are data types that can hold multiple values or objects.
list: Ordered collection of items, mutable
tuple: Ordered collection of items, immutable
dict: Collection of key-value pairs
, set: Unordered collection of unique items
frozenset: Immutable set
iii. User-defined Data Types: These are data types created by the user using classes and
objects. They allow developers to define custom structures and behaviours suited to their
specific needs.
5. List :-
A list in Python is an ordered collection of elements, mutable and accessed by index, typically enclosed in
square brackets `[]`. Lists can contain elements of different data types and support various operations like
appending, slicing, and sorting. We can also define list without using any brackets.
Example:
Characteristics Of lists are :
Ordered: It maintain the order of data insertions
Heterogeneous: It can contain value of different datatypes.
Type: List is both compound(holding values of different datatypes) and sequence(order wise) datatype
Mutable: List is mutable. We can use and update every value through their indexes.
Duplicate: It can contain duplicate values.
Symbol: In list we use [].
Reverse: In list for doing reverse we start counting from the last index as -1 , then second last -2 , so on.
Operations of lists are :-
Merging
Mutability :
S=[1,05,75]
Ab=[‘k’,’l’,’d’]
U=[51,29]
Ab[1]=’j’
St=s+u
Print(ab)
Print(st)
Concatenation
Cloning
1st=[1,2,4]
Searching
1st=1st+[5,9] Comparison
Prinr(1st)
6. Tuple :-
, A tuple in Python is an ordered, immutable collection of elements, defined using parentheses `()`. Tuples
are often used for heterogeneous data and as a lightweight alternative to lists for storing data.
Example:
Characteristics Of Tuple :
Ordered: It maintain the order of data insertions
Heterogeneous: It can contain value of different datatypes.
Type: Tuple is both compound and sequence datatype. Beside it is a read only datatype.
Immutable: Tuples are immutable. We can’t modify or update any value of tuple just like sets.
Duplicate: It can contain duplicate values like sets.
Symbol: In tuples we use ().
Operations of tuple are :-
Count -> tuple_name.count(“name_of_elemnt”)
Concatenation -> final=tuple1+tuple2
7. Dictionary
A dictionary in Python is an unordered collection of key-value pairs, defined using curly braces `{}`.
Keys must be unique and immutable, while values can be of any data type.
This are like hashing (concept of having a key value that tells us about the data location )Here index
can be anything , it can be a string , it can be a number , it can also be a float, or anything.
Example:
Syntax :
tinydict = {'name': 'john' , 'code':6734, }