- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String Data Type in Python
Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.
The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. For example −
#!/usr/bin/python str = 'Hello World!' print str # Prints complete string print str # Prints first character of the string print str[2:5] # Prints characters starting from 3rd to 5th print str[2:] # Prints string starting from 3rd character print str * 2 # Prints string two times print str + "TEST" # Prints concatenated string
This will produce the following result −
Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST
- PHP String Data Type
- Python Pandas - Convert string data into datetime type
- Number Data Type in Python
- List Data Type in Python
- Tuple Data Type in Python
- Dictionary Data Type in Python
- Data Type Conversion in Python
- How to change any data type into a string in Python?
- What is a sequence data type in Python?
- Python – Extract Particular data type rows
- Abstract Data Type in Data Structures
- Check order specific data type in tuple in Python
- Is String a primitive data type or an object in Java?
- How to convert from string to date data type in MongoDB?
- Change data type of given numpy array in Python