
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
Example
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[0] # 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
Output
This will produce the following result −
Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST
- Related Articles
- Python Pandas - Convert string data into datetime type
- PHP String Data Type
- How to change any data type into a string in Python?
- 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
- Python – Extract Particular data type rows
- What is a sequence data type in Python?
- 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
- Get the data type of column in Pandas - Python

Advertisements