Presentation (1)
Presentation (1)
s1 = ""
print(s1)
Accessing string characters in Python:
We can access string characters in Python by using,
1.Indexing
2.Slicing
Python supports two types of indexing.
1.Positive indexing: The position of string characters can be a positive index
from left to right direction (we can say forward direction). In this way, the starting
position is 0 (zero).
2.Negative indexing: The position of string characters can be negative indexes
from right to left direction (we can say backward direction). In this way, the
starting position is -1 (minus one).
index
Accessing a string with an index in Python
wish = "Hello World"
print(wish[0])
print(wish[1])
name ="Python"
for a in name: P
print(a) y
t
h
o
n
Slicing
Slicing operator using several use cases
a = "Python" PythonProgramming
b = "Programming"
print(a+b)
a = "Python"
b=4 can only concatenate str (not "int") to str
print(a+b)
Multiplication operator on Strings in Python:
This is used for string repetition. While using the * operator on
the string, the compulsory one argument should be a string,
and other arguments should be int type.
a = "Python"
b=3 PythonPythonPython
print(a*b)