A data type tells Python what kind of value an object is and what operations it supports. This section covers the basic, single-value types; the collection types follow in the next sections.
Numeric types
Type
Meaning
Examples
int
Whole numbers of unlimited size
-12, 0, 123, 10**20
float
Real numbers, stored as 64-bit binary floating point (like C’s double)
-2.04, 4.0, 1.5e3
complex
Complex numbers; j is the imaginary unit
3+4j, 2-2j
bool
The truth values True and False (a subtype of int: True behaves as 1)
True, False, 10 > 7
Unlike C, Python integers never overflow. Floats, however, are approximate: 0.1 + 0.2 gives 0.30000000000000004.
type(x) shows a value’s type, and isinstance(x, int) tests it.
Type conversion
Function
Example
Result
int()
int("42"), int(3.99)
42, 3 (cuts off the fraction)
float()
float("2.5"), float(3)
2.5, 3.0
str()
str(31)
"31"
bool()
bool(0), bool("hi")
False, True
Converting with these functions is called type conversion or type casting; Python also converts automatically in mixed arithmetic, for example 3 + 2.5 gives the float 5.5.
Strings
'hello' and "hello" are the same; triple quotes """...""" allow several lines.
There is no separate char type: a character is a string of length 1.
len(s) gives the length.
Indexing: s[0] is the first character; negative indexes count from the end, so s[-1] is the last.
Slicing: s[start:stop] gives the characters from start up to but not includingstop; omitted start means 0, omitted stop means the end; s[::-1] reverses.
+ joins strings, * repeats them.
Strings are immutable: s[0] = 'h' raises TypeError; create a new string instead.
Indexes of 'Hello Friend'
H e l l o F r i e n d 0 1 2 3 4 5 6 7 8 9 10 11-12 ... -2 -1
None
None is a special value of type NoneType meaning “no value”. It is what a function returns when it has no return statement, and is often used as a placeholder: money = None. Test for it with is: if money is None:.
Key takeaways
Numbers: int (no overflow), float (approximate), complex, bool.
Strings are immutable sequences; index from 0 or from −1 at the end; slices exclude the stop index.
None represents “no value”; test it with is None.
Convert types explicitly with int(), float(), str(), bool().
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write statements that take s = "Programming" and print its first three characters, its last three characters and the string reversed, and give the outputs.
Show worked answer
print(s[:3]) prints Pro; print(s[-3:]) prints ing; print(s[::-1]) prints gnimmargorP. The slice [:3] stops before index 3, [-3:] starts three characters from the end, and a step of −1 walks the string backwards.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-structures-and-control-statements-in-python/numbers-strings-and-none/ to read this page.