String Type Example
What is the maximum value that can be stored inside a Python string variable?
Below is the Max size
Max size: 8.00 TB
Single line using single quote
Single quote is same as double quote for string data type
Single line using double quote
Single quote is same as double quote for string data type
Multi line using single quote
Multi line statement can be created using 3 single quotes.
Multi line using double quote
Multi line statement can be created using 3 double quotes.
greet = 'welcome';
Slicing Example
Accessing one specific character in string variable
Find the 3rd character from 0th index
c
Number after colon executed with -1
which will be considered as start:stop
Accessing 3rd to 5th specific character in the string variable
Find the characters from 0th index to 5th index
com
Accessing from 0 to 5th specific character in the string variable
Find the characters from 0th index to 5th index
welcom
Accessing from 3rd to end of the string variable
Find the characters from 0th index to last index
come
Accessing from last to 4 characters in the string variable
Find the characters from last index to 4 characters
come
Accessing from last to 4 characters but skip last character in the string variable
Find the characters from last index to 4 characters with skipping last character
come
Iteration Example
Iterate the Greet String and print each character
character: w
character: e
character: l
character: c
character: o
character: m
character: e
Find Length Example
Find a Length of greet String
greet length 7
in / not in
Exist Check Example
Find whether w
string exists in greet variable using in
keyword
Time Complexity: O(n). In Python, strings are typically implemented as arrays of characters. The operation 'w' in greet is essentially a search operation where Python checks each character in the string greet to see if it matches 'w'.
True
Use in
statement in if
statement as well
w exists in greet variable
Use in
statement in if
statement as well
u Not exist in greet variable
Format Example
format() method takes an unlimited number of arguments. Example
I am currently Full Stack engineer at Meta Inc and working in Singapore.
format() with index numbers
hey i work for Meta Inc in Singapore as Full Stack engineer