String Data-type in Python
Strings
In python String is collection of characters under single or double or triple quotes. In python there is nothing like character data type , a single character is a string with length 1. String Data-type in Python is immutable data type which means after assigning value to a variable we can’t modify data from the string variable.
String Data-Type in Python Programming Language :
- For string data type we use str() keyword
- We can perform many operations on String.
- We can add two string data-type using ‘+’ operator.
- We can convert a string into a list then we can append or remove element from them.
- String supports indexing.
- There are several in built functions for strings , namely , replace(), isupper(), islower(), join(), and so on..
Example :
Run
#python #creating a string print('single quotes :') s='Hello Prepsters welcome to PrepInsta' print(s) print("doubel quotes :") s="Hello Prepsters welcome to PrepInsta" print(s) print('''triple quotes :''') s='''Hello Prepsters welcome to PrepInsta''' print(s) print('add operation :') s1= 'Hello Prepsters ' s2='welcom to PrepInsta' s=s1+s2 print(s) print('conver string into list:') x=list(s) print(type(x)) print('Indexing :') s='abcdef' print('first charcter is ;',s[0]) print('last charcter is :' ,s[-1])
Output:
single quotes :
Hello Prepsters welcome to PrepInsta
doubel quotes :
Hello Prepsters welcome to PrepInsta
triple quotes :
Hello Prepsters welcome to PrepInsta
add operation :
Hello Prepsters welcom to PrepInsta
conver string into list:
<class 'list'>
Indexing :
first charcter is ; a
last charcter is : f
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment