Taken from my in depth Python Tutorial for Beginners the following page describes common data types.
Common Python Data Types
- Strings
- Dictionaries
- Numbers
- Booleans
- Lists
- Sets
- Frozensets
- Tuples
- Ranges
- Dictionaries
- None
One way to classify data types is to determine if the data can be changed after creation or not, this is called mutable or immutable.
Mutable data types are:
- Dictonaries
- Lists
- Sets
Immutable data types are:
- Strings
- Numbers
- Tuples
- Frozensets
Python Strings
Probably the most widely used data type. You will certainly use strings in nearly every Python programme you use.
A string in Python is a sequence of characters, letters numbers and other characters enclosed by quotes.
All the examples below are described in this video.
Python Strings Video in hereTo create a string in Python we need to define it as below:
stringexample = "This is a string"
One of the main elements of a string is indexing, as a string is a list of elements you can reference each element in a string by a number, however starting from the left the index of the first element (in our case T) would be 0.
So to access an element in my string above I would enter the command:
stringexample[0]
This would output the value T
Frequently asked questions
What are Strings in Python?
A string in Python is a sequence of characters. It is a derived data type. Strings are immutable. This means that once defined, they cannot be changed. Many Python methods, such as replace() , join() , or split() can modify strings.
How many data types are there in Python?
Python has six standard data types. Numbers, Strings, Lists, Tuples, Sets & Dictionaries.