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

Python Rules

Basic Python Notes

Uploaded by

ZAIEEM KHAN
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)
58 views3 pages

Python Rules

Basic Python Notes

Uploaded by

ZAIEEM KHAN
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

PYTHON RULES

Python is case sensitive because Python use UTF8 (Uniform transformation


formate) (A, a Both are different)
variable can start with character or only
variable/object can hold only numerical, characters and code
variable can have any logical length
don't use reserved key word as a variable like (with, is, or else, and)
1. Indentation:
Python uses indentation to indicate blocks of code. It is crucial for defining the
scape of loops, functions, and conditional statements.
2. Variables and Naming Conventions:
Variables names should be descriptive.
Use lowercase with underscores for variable names (snake case).
Avoid using reserved words (e.g., if, else, while etc.) as variable names
3. Comments:
Use it for single-line comments and’’ or ” ” multi-line comments.
4. Whitespace
Use white space effectively for better readability. Avoid Excessive Spaces.
Ex:- a = 5 #avoid
b= 5 #should follow

Indexing and Slicing


Indexing refers to accessing individual elements in sequence using their position
index . In python , indexing start at 0 You can use square brackets [] to access at
a specific index.
Slicing allows you to create a new sequence by extracting a portion of an
existing sequence. It uses the format start:stop:step , where start is the index of
the first element, stop is the index of the first element not to be included ,and
step is the step size .
List : List is built in data types used to store a collection of items. Lists are
ordered, Mutable (modifiable) and can contain elements of different data
types .They are one of the most versatile and commonly used data structure in
Python.
Heterogeneous Elements
A list can contain elements of different data types, including numbers, strings,
Booleans and even other lists.
My_list=[5,’word’,True,[9,666,78]]
In built functions
i.append () # it will add an element at end
i.insert()
i.extend()
i.pop()
i.clear()
i.remove()
i.sort()
len(): Returns the number of elements in the iterable (e.g., list, tuple, string).
append(x): Adds an element x to the end of the list.
extend(iterable): Extends the list by appending elements from the iterable.
insert(index, element): Inserts an element x at the specified index i in the list.
remove(x): Removes the first occurrence of element x from the list.
pop([i]): Removes and returns the element at index i. If i is not provided, it
removes and returns the last element.
count(x): Retums the number of occurrences of element x in the list.
TUPLE:-
A tuple is a data structure in Python that is similar to a list but is immutable,
meaning its elements cannot be changed after creation. Tuples are defined using
parentheses () and can contain elements of different data types.
SOME IN BUILD FUNCTION
COUNT(): - Returns the number of occurrences of the specified element in the
tuple.
SOME IN BUILD FUNCTION
COUNT(): Returns the number of occurrences of the specified element in the
tuple.
LEN():- Returns the length(no. of elements) in the tuples
MIN(): Return the minimum value of the tuple
MAX():- Return the maximum value of the tuple
SET ()
In Python, a set is an unordered collection of unique elements. It is defined using
curly braces {} or the set() constructor. Sets do not allow duplicate elements,
and they are useful for tasks that involve testing membership and eliminating
duplicate entries.
IN BUILD FUNCITON
UNION:- In Python, the union operation on sets is used to combine the elements
of two or more sets into a new set. The resulting set contains all.
INTERSECTION: -The intersection operation on sets is used to find the common
elements between two or more sets. The resulting set contains only the elements
that are present in all the original sets.
DIFFERENCE: - The difference operation on sets is used to find the elements that
are present in one set but not in another. It computes the set of elements that
are unique to the first set, excluding any elements that are also present in the
second set.
SYMMETRIC_DIFFERENCE: -The symmetric difference operation on sets is used to
find the elements that are present in either of the sets but not in bot It computes
the set of elements that are unique to each set, excluding any elements that are
common to both sets.
Dictionary :- In Python, a dictionary is a mutable, unordered till 3.7 now it is
ordered collection of key-value pairs, where each key must be unique.
Dictionaries are implemented as hash tables, providing fast access to values
based on their keys. You can use dictionaries to store and retrieve data
efficiently.

You might also like