Title: Data Types in Python Part-2
1Data Types in Python
Swipe
2Data Types in Python
Fundamentals
Derived
Integers Float Complex Boolean String None
List Tuple Range Bytes Bytes Arrays Set Frozen
Set Dictionary
Numbers
Sequence
Sequence
Mapping
3Base conversion
To convert any number from binary, octal,
hexadecimal to decimal value just assign the
value to a variable with corresponding prefixed
and peint it. It will give you decimal
equivalent of that number.
Bin(X)
Here argument (x) can be a decimal, octal or
hexadecimal value anything
Basic Conversion
oct(X)
hex(X)
4Boolean
Data type with one of the two built-in values,
True or False. Boolean objects that are equal to
True are truthy (true). But non-Boolean objects
can be evaluated in Boolean context as well and
determined to be true or false. It is denoted by
the class bool.
Python program to demonstrate boolean
type print(type(True)) print(type(False)) print(
type(True))
5Boolean Data Type in Python
Note True and False with capital T and F are
valid booleans otherwise python will throw an
error.
Boolean in python
True False
- Except 0 everything is true
- Except empty string everything is true
True - 1 False - 0
6Strings in Python
- In Python, Strings are arrays of bytes representin
g Unicode characters. - A string is a collection of one or more
characters put in a single quote, double-quote
or triple quote. - In python there is no character data type, a
character is a string of length one. - It is represented by str class.
7Strings in Python
Combination of characters kept inside
single/double/triple quotes.
Triple quotes are used to -To define multiline
string, -To define docstring. -To comment
multiple lines.
Strings
Indexing - strindex Slicing -
startendstep Few basic operation on
string. -Concatenation. -Repetition.
8Topics for next Post
Data Types in Python Mutable vs Immutable Data
type in Python Stay Tuned with