You are on page 1of 4

name= "hello"

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 \nworld") # \n used to get new line

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'

x.split('i') # based on i so removes i


print('hello')
# print formatting with Strings
# .format()
# f-strings( formatted string literals)

# syntax :-
# 'string here {} then also {}'.format('something1', 'something2)

print('This is a string {}'.format('inserted'))


print('The {2} {1} {0}'.format('fox','brown','quick')

# Float Formatting follows value width precision

result = 100/777
result
print('the result was {r}'.format(r = result))

print('the result was {r:10.6f}'.format(r = result))

# fstring literalls
name = 'sam'
age = 5

print(f'{name} is {age} years old')

############################### List ################################

# list are ordered sequence of elements that can hold different


# data type objects

list1 = ['Python', 'DataScience', 2013, 2018]


list1
print(list1)
list2 = [1, 2, 3, 4, 5 ]
list3 = ["a", "b", "c", "d"]

python_class = ["Basics", "of", "Python"]

list1 = ['of', 'Basics', 2014, 2018]

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])

list1 = ['Python', 'Basics', 2013, 2018]


print(list1[2])
list1[2] = 22334
list1[2] = 8888
list1
list1[2] = 8055
print(list1)
k= 10.5e5
#10.5e2=10.5*pow(10,2)= 10.5*100=1050.0
print(k)
9**2
pow(9,2)
y= 9**2
y
k
k=5
x = 2*k
print(x)
list1[0] = "Basics"
list1
list1 = ['Python', 'Basics', 2013, 2018]
print(list1)
del(list1)
list1
print(list1)

# Append

aList = [123, 'xyz', 'zara', 'abc']


aList.append( 2009 )
aList
aList.append(444)
print(aList)

#Pop # it will the last element of the list

aList.pop()
print(aList)
aList
aList.pop(2)
aList

############Insert

aList.insert(3,2010)
print (aList)

aList.insert(2,"Anjali")
print (aList)

#Extend

aList = [123, 'xyz', 'tommy', 'abc', 123]


bList = [2009, 'beneli']

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

aList = [123, 'xyz', 'zara', 'abc', 123, "zara",1,1,1,1,1,1,1,1,1,1]


aList.count('zara')
print(aList.count(1))

You might also like