If a software language is easy in terms of declaring variables, then consider that half of the time and efforts are saved. Python is one of the easiest and convenient languages for declaring variables.”
If a software language is easy in terms of declaring variables, then consider that half of the time and efforts are saved. Python is one of the easiest and convenient languages for declaring variables.”
If a software language is easy in terms of declaring variables, then consider that half of the time and effort are saved. Python is one of the easiest and most convenient languages for declaring variables. We will dive deep into the variables of Python, their rules of declaration, and basic information about variables.
=
operator.# Declare string
name='john doe'
name
'john doe'
Python# Declaring integer
num=5
num
5
Python# Declaring Float
pi=3.14
pi
3.14
PythonWhat to consider before naming variables?
Rule 1: Variable names must not start with numbers.
# declare variable five
five=5
print(five)
5
Python# declare variable f5
f5=5
print(f5)
5
PythonRule 2: Variable names must not include these special symbols.
, < > / + @ – ‘ “” : ? # % ^ & * ~ | \ !
# using special symbol & in variable.
jacknjill='hill'
# using special symbol @ in variable.
johndoemail='johndoe@gmail.com'
print(jacknjill)
print(johndoemail)
hill
johndoe@gmail.com
PythonRule 3: Names cannot contain spaces; use _ instead.
# avoid using special symbol @ in variable.
john_doe_at_age=20
# use _ instead of blank spaces.
john_doe_age=20
print(john_doe_at_age)
print(john_doe_age)
20
20
PythonRule 4: Variable names must not contain Python’s keywords.
# Don't use a keyword for a variable.
if=5
File "<ipython-input-9-5719a260f2d6>", line 2
if=5
^
SyntaxError: invalid syntax
Python# Assign multiple variables the same value at once.
d=e=f=110
print(d)
print(e)
print(f)
110
110
110
Pythonpi=3.14 # Store value of pie in pi
print(pi)
3.14
Python# print type of pi
type(pi)
float
PythonLet’s change pi’s datatype to an integer with int().
# type cast pi into integer
int(pi)
3
PythonLet’s convert a number stored in string format to an integer with int().
# store string in alphabets
alphabets='6798'
print(alphabets)
print(type(alphabets))
# typecast alphabets into integer.
int(alphabets)
6798
<class 'str'>
6798
PythonLet’s explain the local variable with a simple function.
# element1 is global variable.
# element2 is local variables in the chemist function.
element1 = "methane"
def chemist():
element2 = "ethane"
element2 = element2 + element1
print(element2)
chemist()
ethanemethane
PythonAs you see above, the variable element1 is declared above the scope of chemist(), so it is available to all child
scopes in it.
Element2 is declared in the chemist() function, so it is exclusive to the chemist() and its child scopes only.
print(element1)
methane
PythonIf you try to access local variables outside their scope, this error will occur, but element 1 is accessed in the function despite being in a different scope. Because it was accessed within its sub-scope. You can access the variables from the parent scopes.
There is a way to access the local scope variables outside the scope. If we declare the local variables as global with a global
keyword.
# element1 is global variable.
# element2 is local variables in the chemist function.
element1 = "methane"
def chemist():
global element2
element2 = "ethane"
element2 = element1 + element2
return element2
chemist()
print(element2)
methaneethane
Python# accessing element2 has been made global
print(element2)
# access the local variable through chemist() function.
print(chemist())
methaneethane
methaneethane
PythonAs you can see above, if you declare a variable with the global keyword, it becomes accessible in all scopes. Be careful with using global; it may create discrepancies in the security of working systems.
You can delete a variable in Python by using the ‘del'
keyword.
Syntax: del variable_name
#store value of pie
pie=3.146
print(pie)
3.146
Python# delete pie
del pie
%who pie
No variables match your requested type.
PythonIn the above code, we used %who pie to find the deleted variable.
ANCOVA is an extension of ANOVA (Analysis of Variance) that combines blocks of regression analysis and ANOVA. Which makes it Analysis of Covariance.
What if we learn topics in a desirable way!! What if we learn to write Python codes from gamers data !!
Start using NotebookLM today and embark on a smarter, more efficient learning journey!
This can be a super guide for you to start and excel in your data science career.
A method to find a statistical relationship between two variables in a dataset where one variable is used to group data.
Seaborn library has matplotlib at its core for data point visualizations. This library gives highly statistical informative graphics functionality to Seaborn.
The Matplotlib library helps you create static and dynamic visualisations. Dynamic visualizations that are animated and interactive. This library makes it easy to plot data and create graphs.
This library is named Plotly after the company of the same name. Plotly provides visualization libraries for Python, R, MATLAB, Perl, Julia, Arduino, and REST.
Numpy array have functions for matrices ,linear algebra ,Fourier Transform. Numpy arrays provide 50x more speed than a python list.
Numpy has created a vast ecosystem spanning numerous fields of science.
Pandas is a easy to use data analysis and manipulation tool. Pandas provides functionality for categorical,ordinal, and time series data . Panda provides fast and powerful calculations for data analysis.
In this tutorial, you will learn How to Access The Data in Various Ways From the dataframe.
Understand one of the important data types in Python. Each item in a set is distinct. Sets can store multiple items of various types of data.
Tuples are a sequence of Python objects. A tuple is created by separating items with a comma. They are put inside the parenthesis “”(“” , “”)””.