#Python #variables #type
Why learn Python?
Programmers love Python because of how fast and easy it is to use. Python cuts development time in half with its simple to read syntax and easy compilation feature. Debugging your programs is a breeze in Python with its built in debugger. Using Python makes Programmers more productive and their programs ultimately better.
Python has evolved as the most preferred Language for Data Analytics and the increasing search trends on python also indicates that Python is the next "Big Thing" and a must for Professionals in the Data Analytics domain.
What are variables?
4 basic data types
integers
floats
strings
booleans
tips & tricks
In this lecture we are discussing about DataTypes in Python:
-- why it is important?
-- how to use it ?
Python has several built-in data types. Here are some of the most common ones:
i) NoneType: This is a special data type that represents the absence of a value. It is similar to null in other languages.
ii) Numbers: These can be integers, floating-point numbers, or complex numbers.
iii) Booleans: These are values that represent True or False.
iv) Lists: These are ordered collections of objects, enclosed in square brackets.
v) Tuples: These are similar to lists, but are immutable (i.e., their contents cannot be changed), and are enclosed in parentheses.
vi) Sets: These are unordered collections of unique elements, enclosed in curly braces.
vii) Strings: These are sequences of characters, enclosed in single or double quotes.
viii) Ranges: These are immutable sequences of numbers, and are commonly used to iterate over a sequence of numbers in a for loop.
ix) Dictionaries: These are collections of key-value pairs, enclosed in curly braces.
Note:In addition to these built-in data types, Python also allows you to define your own custom data types using classes.
i)None Type
a=None
type(a)
ii)Numbers
int: if you want to assign a integer value to a variable
a=5
type(a)
float: if you want to assign a float value to a variable
num =2.5
type(num)
complex: if you want to assign a complex value to a variable
num =2+9j
type(num)
type conversion: if you want to convert one data type to another data type
a=5.6
b=int(a)
type(b) # output : int
k=float(b)
type(k) # output : float
c=complex(4,5)
type(c) # output : complex
iii)boolean: if you want to assign a variable with a boolean value
a= True
type(a) # output : bool
bool=3 less then5
True
type(bool)
e
vii) String: if you want to assign sequence of characters to a variable
-- In Python, a string is a sequence of characters enclosed in single or double quotes.
Strings are immutable, which means that they cannot be modified once they are created.
str = "hello"
type(str) # output : str
we are not talk about char data type in python
st='a' # every character is a string in python
13 сен 2023