PYTHON3
PYTHON3
The pass statement is also known as the null statement. The Python mediator
doesn't overlook a Remark, though a pass proclamation isn't. As a result, these two
Python keywords are distinct.
We can use the pass statement as a placeholder when unsure of the code to provide.
Therefore, the pass only needs to be placed on that line. The pass might be utilized
when we wish no code to be executed. We can simply insert a pass in cases where
empty code is prohibited, such as in loops, functions, class definitions, and if-else
statements.
Syntax
Keyword:
pass
Code
# Python program to show how to use a pass statement in a for loop
'''''pass acts as a placeholder. We can fill this place later on'''
sequence = {"Python", "Pass", "Statement", "Placeholder"}
for value in sequence:
if value == "Pass":
pass # leaving an empty if block using the pass keyword
else:
print("Not reached pass keyword: ", value)
Python String
Python string is the collection of the characters surrounded by single quotes,
double quotes, or triple quotes. The computer does not understand the
characters; internally, it stores manipulated character as the combination of the 0's
and 1's.
Syntax:
Like other languages, the indexing of the Python strings starts from 0. For
example, The string "HELLO" is indexed as given in the below figure.
example:
str = "HELLO"
print(str[0])
print(str[1])
print(str[2])
print(str[3])
print(str[4])
# It returns the IndexError because 6th index doesn't exist
print(str[6])
In Python, the slice operator [] is used to access the individual characters of the
string. However, we can use the : (colon) operator in Python to access the substring
from the given string.
Example.
# Given String
str = "WELCOME TO SGHITI"
# Start Oth index to end
print(str[0:])
# Starts 1th index to 4th index
print(str[1:5])
# Starts 2nd index to 3rd index
print(str[2:4])
# Starts 0th to 2nd index
print(str[:3])
#Starts 4th to 6th index
print(str[4:7])
We can do the negative slicing in the string; it starts from the rightmost character,
which is indicated as -1. The second rightmost index indicates -2, and so on.
Consider the following image.
example
Python List
In Python, the sequence of various data types is stored in a list. A list is a collection
of different kinds of values or items. Since Python lists are mutable, we can change
their elements after forming. The comma (,) and the square brackets [enclose the
List's items] serve as separators.
Although six Python data types can hold sequences, the List is the most common
and reliable form. A list, a type of sequence data, is used to store the collection of
data. Tuples and Strings are two similar data formats for sequences.
# a simple list
list1 = [1, 2, "Python", "Program", 15.9]
list2 = ["Amy", "Ryan", "Henry", "Emma"]
Characteristics of Lists
o The lists are in order.
o The list element can be accessed via the index.
o The mutable type of List is
o The rundowns are changeable sorts.
o The number of various elements can be stored in a list.
list = [1,2,3,4,5,6,7]
print(list[0])
print(list[1])
print(list[2])
print(list[3])
# Slicing the elements
print(list[0:6])
# By default, the index value is 0 so its starts from the 0th element and go for in
dex -1.
print(list[:])
print(list[2:5])
print(list[1:6:2])
Due to their mutability and the slice and assignment operator's ability to update
their values, lists are Python's most adaptable data structure. Python's append()
and insert() methods can also add values to a list.
APNE AAP KO EK BAAR FIR PAGAL PROVE MAT KARNA JO KAHA VO LIKHNA
JO EXAMPLE BATYA HAI VAHI LIKHNA
APNE AAP KO EK BAAR FIR PAGAL PROVE MAT KARNA JO KAHA VO LIKHNA
JO EXAMPLE BATYA HAI VAHI LIKHNA
3. Length
4. Iteration
print(600 in list1)
print(700 in list1)
print(1040 in list1)
print(300 in list1)
print(100 in list1)
print(500 in list1)
list = [0,1,2,3,4]
print("printing original list: ");
for i in list:
print(i,end=" ")
list.remove(2)
print("\nprinting the list after the removal of first element...")
for i in list:
print(i,end=" ")
len( )
Max( )
# maximum of the list
list1 = [103, 675, 321, 782, 200]
# large element in the list
print(max(list1))
Min( )