Professional Documents
Culture Documents
print(name)
index start from 0 and n-1
h e l l o
0 1 2 3 4
name[0]
name[4]
# reverse indexing
name[-1]
name[-2]
name[-3]
name[-4]
name[-5]
olleh
my_string = "abcdefghijk"
dtype(my_string) # datatype
str
len(my_string) # 11
print(my_string)
abcdefghijk
# indexing of string/numeric
slicing array
my_string[2:]
output:cdefghijk
my_string[6:]
output:fghijk"
my_string[:7]
abcdefgh
my_string[:8]
abcdefghi
ex: a[([1,2,3] [4,5,6]),(7,8,9)]
0 1 2
slicing [1:0:2]
slicing 0 1 2
4 5 6
slicing[0,0:1]
1 2
import numpy
a=numpy.array([1,2,3,4])
a[0:0:3]
# reverse the string
my_string[::-1]
print("hello \tworld")
# string immutability
name = "sam"
last_letters = name[1:]
'p'+last_letters # string concatenation
'2'+'3'
x = "Hello World"
len(x)
x.upper() # upper case
x.lower() # lower case
x.split() # splitting string based on white space
x = 'hi this is a string'
# syntax :-
# 'string here {} then also {}'.format('something1', 'something2)
result = 100/777
result
print('the result was {r}'.format(r = result))
# fstring literalls
name = 'sam'
age = 5
print(list1[0])
list1[0]
print(list1[-3])
my_list = ['one','two','three']
my_list[2]
my_list[1:]
# append()
my_list.append("four")
my_list
my_list.extend("five")
# remove the last item of the list
my_list.pop()
my_list.pop(0)
my_list.pop(-1)
my_list
# reverse()
my_list.reverse()
my_list.sort()
list2 = [13, 42, 53, 34, 25, 86, 79 ]
list2.sort()
print(list2)
list2.append(100)
list2.extend('121')
print(list2)
print(list2[0:3])
# Append
aList.pop()
print(aList)
aList
aList.pop(2)
aList
############Insert
aList.insert(3,2010)
print (aList)
aList.insert(2,"Anjali")
print (aList)
#Extend
bList.extend(aList)
aList.append(bList)
aList.extend(bList)
print(aList)
#Reverse
aList.reverse()
print(aList)
#Sort
blist = [8,99,45,33]
blist.sort(reverse = False)
print(blist)
#count