Python Article
Python
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in datastructures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance.
Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.
Python 3 basics
Python was developed by Guido van Rossum in the early 1990s and its latest version is 3.10.4, we can simply call it as Python3. Python 3.0 was released in 2008. and is interpreted language i.e it’s not compiled and the interpreter will check the code line by line. This article can used to learn very basics of Python programming language.
Looping Techniques in Python
Python supports various looping techniques by certain inbuilt functions, in various sequential containers. These methods are primarily very useful in competitive programming and also in various projects which require a specific technique with loops maintaining the overall structure of code. A lot of time and memory space is been saved as there is no need to declare the extra variables which we declare in the traditional approach of loops.
Python Keywords
Keywords in Python are reserved words that can not be used as a variable name, function name, or any other identifier.
Iteration Keywords
for:- This keyword is used to control flow and for looping. while:- Has a similar working like “for”, used to control flow and for looping. break:- “break” is used to control the flow of the loop. The statement is used to break out of the loop and passes the control to the statement following immediately after loop. continue:- “continue” is also used to control the flow of code. The keyword skips the current iteration of the loop but does not end the loop.
Conditional keywords
if :- It is a control statement for decision making. Truth expression forces control to go in “if” statement block. else :- It is a control statement for decision making. False expression forces control to go in “else” statement block. elif :- It is a control statement for decision making. It is short for "else if".
Return Keywords
-return :- This keyword is used to return from the function. -yield :- This keyword is used like return statement but is used to return a generator.
Exception Handling Keywords
try :-This keyword is used for exception handling, used to catch the errors in the code using the keyword except. Code in “try” block is checked, if there is any type of error, except block is executed. except :-As explained above, this works together with “try” to catch exceptions. finally :-No matter what is result of the “try” block, block termed “finally” is always executed. raise:-We can raise an exception explicitly with the raise keyword. assert:-This function is used for debugging purposes. Usually used to check the correctness of code. If a statement is evaluated to be true, nothing happens, but when it is false, “AssertionError” is raised. One can also print a message with the error, separated by a comma.
Operators
Python Operators in general are used to perform operations on values and variables. These are standard symbols used for the purpose of logical and arithmetic operations. In this article, we will look into different types of Python operators.
Taking input in Python
input ( ) : This function first takes the input from the user and convert it into string. Type of the returned object always will be For example –
# a use of input()
val = input("Enter your value: ")
print(val)
A string is a sequence of characters. It can be declared in python by using double-quotes. Strings are immutable, i.e., they cannot be
changed.
# Assigning string to a variable
a = “This is a string”
print (a) Iterations or looping can be performed in python by ‘for’ and ‘while’ loops. Apart from iterating upon a particular condition, we can also
iterate on strings, lists, and tuples. Example : Iteration by while loop for a condition
i = 1
while (i < 10): print(i) i +=1 The output is : 1 2 3 4 5 6 7 8 9 A tuple is a sequence of immutable Python objects. Tuples are just like lists with the exception that tuples cannot be changed once declared.
Tuples are usually faster than lists. tup = (1, “a”, “string”, 1+2)
print(tup)
print(tup[1])
The output is :
(1, ‘a’, ‘string’, 3)
a Python has predefined functions for many mathematical, logical, relational, bitwise etc operations under the module
“operator”. Some of the basic functions are covered in this article. 1. add(a, b) :- This functions returns addition of the given arguments.
Operation – a + b.
2. sub(a, b) :- This functions returns difference of the given arguments.
Operation – a – b.
3. mul(a, b) :- This functions returns product of the given arguments.
Operation – a b. Python Functions is a block of related statements designed to perform a computational, logical, or evaluative task. The idea is to put
some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different inputs,
we can do the function calls to reuse code contained in it over and over again. Functions can be both built-in or user-defined. It helps the program to be concise, non-repetitive, and organized. Syntax:
def function_name(parameters):
"""docstring"""
statement(s)
return expression While Python itself is just a programming language, a Python distribution bundles the core language with various other libraries and packages generally geared toward a
specific problem domain (such as Data Analytics or Web Development). The standard Python distribution is released on python.org and includes the Python standard library
as well as the package manager pip.
Though the list of Python distributions is always growing, two other popular distributions are Anaconda and Miniconda. Anaconda is an open source Python distribution that is purpose built for data science, machine learning, and large-scale data processing. It includes the core Python language,
over 1,500 data science packages, a package management system called conda, IPython (an interactive Python interpreter), and much more. While it is a very comprehensive distribution,
it is also quite large and therefore can take a while to download and consumes a lot of disk space.
Miniconda on the other hand, is a slimmed down version of Anaconda and includes all of the same components except for the pre-installed 1,500 data science packages. Instead, we can
simply install these packages individually as needed using conda (the Anaconda/Miniconda package manager). We essentially get all the benefits of Anaconda, but without the hassle and
burden of the large size. Feel free to use either distribution, however Miniconda is probably the better choice for getting set up with the least amount of fuss.
Now that we have a Python distribution installed and were able to run some Python code, let’s install the Jupyter Notebook package. Jupyter Notebook is an open-source web application
that allows us to create and share documents that contain live code, equations, visualizations and narrative text. This is a fantastic way to both learn and share Python code and the
installation is made easier by our package installer! The installation steps differ depending on which Python distribution we installed above, so be sure to jump to the appropriate section.
If you have both pip and Miniconda installed, we recommend using Miniconda to install the Jupyter Notebook package.
While Python the language is a great tool, a huge benefit of the Python is the large ecosystem and plethora of reusable packages (sometimes called libraries) that other developers maintain and share for anyone’s use. A package
manager is the tool by which packages can be downloaded, installed, and managed within your projects. It is also responsible for keeping track of package versions and dependencies, packages that we don’t install ourselves but
are imported by the package we’re installing. Even though a package manager is a complex tool, they are very simple to use. Similar to how there are many different Python distributions, there are also several different package
managers available. Despite having several options, most package managers function in the same manner and use a simple command structure. Each Python distribution is usually bundled with a specific package manager. Some of the
more common ones are pip and conda.
Python NumPy is a general-purpose array processing package which provides tools for handling the n-dimensional arrays. It provides various computing tools such as comprehensive mathematical functions,
linear algebra routines. NumPy provides both the flexibility of Python and the speed of well-optimized compiled C code. It’s easy to use syntax makes it highly accessible and productive for programmers from any background.
FOR MORE INFORMATION "C" LANGUAGE GO TO THE VIDEO SECTION AND WATCH ANY VIDEO
Data Types
1)Strings in Python-
2)Iterations in Python-
3)Tuples in Python-
Operator Functions in Python
Python Functions
Python Distribution
Anaconda vs. Miniconda
Jupyter Notebook
Package Manager
NumPy in Python