Que 1. What Is Python?: 1) Easy To Learn and Use
Que 1. What Is Python?: 1) Easy To Learn and Use
Feachers:
2) Expressive Language
Python language is more expressive means that it is more understandable and
readable.
3) Interpreted Language
Python is an interpreted language i.e. interpreter executes the code line by line at a
time. This makes debugging easy and thus suitable for beginners.
4) Cross-platform Language
Python can run equally on different platforms such as Windows, Linux, Unix and
Macintosh etc. So, we can say that Python is a portable language.
6) Object-Oriented Language
Python supports object oriented language and concepts of classes and objects come
into existence.
7) Extensible
It implies that other languages such as C/C++ can be used to compile the code and
thus it can be used further in our python code.
10) Integrated
It can be easily integrated with languages like C, C++, JAVA etc.
Uses of python:
1. Applications:
Python can be used to develop different applications like web applications, graphic user
has features, which also support various concepts of functional programming language. It is
used for dynamic type system and automatic memory management. Python language features
and programming paradigms allow you for developing the small as well as large applications. It
makes the developers use Python over other languages. The standard library helps in using the
different range of modules available for Python. As this module helps you in adding the
functionality without writing any more code. To get the information about various modules,
documentation on python standard library can be referred. While developing any web
application, implementing web services, performing string operations and other usages like
mainly for developing applications. With help of python interpreters, python code can be run on
specific platforms and tools as it supports many operating systems. As python is an interpreted
high-level programming language and it allows you to run the code on multiple platforms. The
new and modified code can be executed without recompiling and its impact can be monitored
or checked. It means it’s not required to recompile the code after every change. This feature
5. Access of Database:
Uses of Python also helps in accessing the database easily. Python helps in customizing the
interfaces of different databases like MySQL, Oracle, Microsoft SQL Server, PostgreSQL, and
other databases. It has an object database like Durus and ZODB. It is used for standard
6. Code Readability:
Python code is easy to read and maintained. It is easily reusable as well wherever it is required.
Python’s having simple syntax, which allows the different concepts to develop without writing
any additional code. The code should be of good quality and easy to maintain the source code
and simplify the maintenance, which is required to develop the software application. It also
emphasizes code readability, which is the great feature, unlike other programming languages. It
helps in building custom applications and clean code helps in maintaining and updating the
like scientific and numeric application, and for both desktop and web applications. Python has
features like analyzing data and visualization, which helps in creating custom solutions without
putting extra effort and time. It helps you to visualize and present data in an effective way.
development significantly. There are many open source applications of python frameworks,
libraries, and development tools for developing the application without putting extra cost.
Python frameworks simplify and make the process faster for web application development and
the frameworks are Django, Flask, pyramid etc. Python GUI frameworks are available for
approach. The test cases can be easily written before any code development. Whenever the
code development started, the written test cases can start testing the code simultaneously and
provides the result. These can also be used for checking or testing the pre-requirements based
artificial intelligence, data analysis, machine learning, face detection, color detection, 3D CAD
applications, console-based applications, audio-based applications, video-based applications,
enterprise applications, and applications for Images etc. These are some major applications
used.
It means it executes the code line by line. Python provides a Python Shell (also known
as Python Interactive Shell) which is used to execute a single Python command and get the
result. Python Shell waits for the input command from the user.
Python provides a Python Shell (also known as Python Interactive Shell) which is
Python Shell waits for the input command from the user. As soon as the user enters
the command, it executes it and displays the result.
As you can see, a Python Prompt comprising of three Greater Than symbols (>>>)
appears. Now, you can enter a single statement and get the result. For example,
enter a simple expression like 3 + 2, press enter and it will display the result in the
next line.
Python slice()
The slice() constructor creates a slice object representing the set of indices specified by
range(start, stop, step). The slice object is used to slice a given sequence (string,
bytes, tuple, list or range) or any object which supports sequence protocol (implements
__getitem__() and __len__() method).
The slice object is used to slice a given sequence (string, bytes, tuple, list or range) or any
object which supports sequence protocol (implements __getitem__() and __len__() method).
Slice object represents the indices specified by range(start, stop, step).
slice(stop)
slice() Parameters
slice() mainly takes three parameters which have the same meaning in both constructs:
Single-line comments are created simply by beginning a line with the hash (#) character, and
they are automatically terminated by the end of line. Comments that span multiple lines – used
to explain things in more detail – are created by adding a delimiter (“””) on each end of
the comment.
When working with any programming language, you include comments in the code to notate
your work. This details what certain parts of the code are for, and lets other developers – you
included – know what you were up to when you wrote the code. This is a necessary practice,
and good developers make heavy use of the comment system. Without it, things can get real
confusing, real fast.
How to Write Comments in Python
In Python, there are two ways to annotate your code.
The first is to include comments that detail or indicate what a section of code – or snippet –
does.
The second makes use of multi-line comments or paragraphs that serve as documentation for
others reading your code.
Think of the first type as a comment for yourself, and the second as a comment for others.
There is not right or wrong way to add a comment, however. You can do whatever feels
comfortable.
Single-line comments are created simply by beginning a line with the hash (#) character, and
they are automatically terminated by the end of line.
For example:
The print() function prints the specified message to the screen, or other standard
output device. The message can be a string, or any other object, the object will be
converted into a string before written to the screen.
Syntax
print(object(s), separator=separator, end=end, file=file, flush=flush)
Example
print() Parameters
objects - object to the printed. * indicates that there may be more than one object
sep - objects are separated by sep. Default value: ' '
end - end is printed at last
file - must be an object with write(string) method. If omitted it, sys.stdout will be used which
prints objects on the screen.
flush - If True, the stream is forcibly flushed. Default value: False
In any OOP language, there are many different data types. In Python, number data types are
used to store numeric values. There are four different numerical types in Python:
1. int (plain integers): this one is pretty standard -- plain integers are just positive or
negative whole numbers.
2. long (long integers): long integers are integers of infinite size. They look just like plain
integers except they're followed by the letter "L" (ex: 150L).
3. float (floating point real values): floats represent real numbers, but are written with
decimal points (or scientific notation) to divide the whole number into fractional parts.
4. complex (complex numbers): represented by the formula a + bJ, where a and b are
floats, and J is the square root of -1 (the result of which is an imaginary number).
Complex numbers are used sparingly in Python.
5. Python supports integers, floating point numbers and complex numbers. They are
defined as int, float and complex class in Python.
6. Integers and floating points are separated by the presence or absence of a decimal
point. 5 is integer whereas 5.0 is a floating point number.
7. Complex numbers are written in the form, x + yj, where x is the real part and y is the
imaginary part.
> Greater than: True if left operand is greater than the right x>y
< Less than: True if left operand is less than the right x<y
>= Greater than or equal to: True if left operand is greater than or equal to the right x >= y
<= Less than or equal to: True if left operand is less than or equal to the right x <= y
3. Logical operators: Logical operators perform Logical AND, Logical OR and Logical
NOT operations.
and Logical AND: True if both the operands are true x and y
| Bitwise OR x|y
~ Bitwise NOT ~x
Data Structures (list, dict, tuples, sets, strings) . The built ins data structures are: lists,
tuples, dictionaries, strings, sets and frozen sets. Lists, strings and tuples are ordered
sequences of objects. Unlike strings that contain only characters, list and tuples can
contain any type of objects.
There are quite a few data structures available. The builtins data structures are:
lists, tuples, dictionaries, strings, sets and frozensets.
Lists, strings and tuples are ordered sequences of objects. Unlike strings that
contain only characters, list and tuples can contain any type of objects. Lists and
tuples are like arrays. Tuples like strings are immutables. Lists are mutables so
they can be extended or reduced at will. Sets are mutable unordered sequence of
unique elements whereas frozensets are immutable sets.
Lists are enclosed in brackets:
l = [1, 2, "a"]
Tuples are enclosed in parentheses:
t = (1, 2, "a")
Tuples are faster and consume less memory. See Tuples for more information.
Dictionaries are built with curly brackets:
d = {"a":1, "b":2}.