DEV Community

Mary-softeng
Mary-softeng

Posted on

Python Basics, Pythons 101!

Definition to Python
Python is a general purpose language which has a wide range of applications from web development, scientific and mathematical computing (orange, SymPy, NumPy) to desktop graphical user interfaces such as pygame. Python programs have the extension .py and can be run from the command line by typing python file_name.py.

Python Features
1.A simple language which is easier to learn.
Python has a very simple and elegant syntax which is much easier to read and write python programs compared to other programming languages. Python makes programming fun and allows you to focus on the solution rather than the syntax.
2.Fee and open source-You can use freely use and distribute python, even for commercial use.
3.Extensible and Embeddable-When an application requires high performance, you can easily combine pieces of C\C++ or other languages with python code. This will give your application high performance as well as scripting capabilities which other languages may not provide out of the box.
4.A high-level, interpreted language-When you run python code, it automatically converts your code to the language your computer understands.
5.Large standard libraries to solve common tasks-Python has a number of standard libraries which makes life of a programmer much easier since you do not have to write all the
code yourself. Example, when you want to connect MySQL database on a web server, you can use MySQL library by using import MySQLdb.
6.Object oriented-Everything in python is an object and this helps you to solve a complex problem intuitively.

Applications of Python.

  1. Web Application. You can create scalable Web Applications using frameworks and Content Management System (CMS) that are built on python. Some of these platforms are Django, flask, pyramid, plone.
  2. Scientific and numeric Computing. There are numerous libraries available in python for scientific and numeric computing

Python Identifiers
A python identifier is a name used to identify a variable, function, class, module or other object. The following are the naming conversions for python identifiers:
• Class names starts with an uppercase letters and all other identifiers with lowercase letters.
• Starting an identifier with a single leading underscore indicates that the identifier is private.
• Starting an identifier with two leading underscores indicates a strongly private identifier.

Reserved Words
Reserved words cannot be used as constants or variable or any other identifier names. All the python keywords contain lowercase letter only eg:
and
exec
assert
finally
break
for
class
from
continue
global
def
if
del
import
elif
in
else
except
lambda.

Lines and indentation
Blocks of code are denoted by line indentation which is rigidly enforced. The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount.

Multi-line Statements
Statements in Python typically ends with a new line. However, python allows the use of line continuation character () to dente that the line should continue.

Quotation in Python
Python accepts single (‘), double (“) and triple (‘”) quotes to denote string literals as long as the same type of quote starts and ends the string. The triple quotes are used to span the string across multiple lines.

Comments in Python.
A hash sign (#) that is not inside a string literal begins a comment. All characters after the # and up to the end of the physical line are part of the comment and python interpreter ignores them.Triple quotes (‘’’) are used when commenting a block of statement
image
Alt Text

Python Variables.
Variables are reserved memory locations to store values.
Assigning values to variables.
The equal sign (=) is used to assign values to variables. The operand to the left is the name of the variable and the operand to the right of the = operator is the value stored in the variable.

Multiple Assignment
Python allows you to assign value to several variables simultaneously.
Alt Text
Here, an integer object is created with the value 1 and all three variables are assigned to the same memory location.
You can also assign multiple objects to multiple variables eg

Here, two integer objects with values 1 and 2 are assigned to variables a and b respectively and one string object with value “John” is assigned to the variable c.
Python Data Types.
Python has five standard data types which includes:
• Numbers
• String
• List
• Tuple
• Dictionary

Python Numbers
Number data types store numeric values. Number objects are created when you assign a value to them.

Python supports four different numerical types.
• Int (signed integers)
• Long (long integers, they can also be represented in octal and hexadecimal)
• Float 9floating point real values)
• Complex (complex numbers)
Alt Text

Python strings
Strings in python are identified as contiguous set of characters represented in quotation marks.
The plus (+) sign is the string concatenation operator and the asterisk (*) is the repletion operator.
Alt Text

Python Operators
Arithmetic: +, -, *, /, and % (modulus)
Alt Text

Comparison: ==! =, <, >, <=, >=
Alt Text

Logical: and, or, not
Alt Text

Exponentiation: **
Execution: os.system ('ls -l')

https://colab.research.google.com/drive/1bXEWeKALGuY0h9kOd6PCFQ9THMNSP-FU?usp=sharing

Top comments (0)