Python overview
Python basic overview
Origin of Python
While employed at Centrum Wiskunde & Informatica (CWI) in the Netherlands in the late 1980s, Dutch programmer Guido van Rossum developed Python. During the 1989 Christmas break, he began the project as a hobby, and it was first published in 1991.
Benefits of Python
Python’s popularity and broad adoption can be attributed to its many advantages:
· Python’s easy-to-learn and easy-to-use syntax: Which is frequently compared to English, makes it a perfect language for novices and speeds up development for more seasoned programmers.
· Versatility and Broad Use: Python is a multi-paradigm language that is utilized in a variety of domains, including automation, scripting, game development, data science and machine learning (NumPy, Pandas, TensorFlow), and web development (Django, Flask), among others.
· Numerous Libraries and Frameworks: Python has a robust library and framework ecosystem that offers pre-built features, saving time and effort during development. Scikit-learn for machine learning, NumPy for numerical computation, and Django, Flask for web development are a few examples.
· Cross-Platform Compatibility: Without requiring major changes, Python code can run smoothly on a variety of operating systems, such as Windows, macOS, and Linux.
· Strong Community Support: Python has a sizable and vibrant international developer community that makes it simpler to learn and solve problems by contributing to its development, producing resources, and providing support.
· Enhanced Productivity: Python’s rich libraries and simple syntax allow programmers to accomplish more with fewer lines of code, which boosts output and speeds up project completion.
· Integration Capabilities: Python can readily interface with a variety of technologies and other programming languages, such as C, C++, and Java, enabling adaptable and potent solutions.
· Free and Open Source: Python is an open-source language, which encourages creativity and accessibility by being freely usable and distributable.
Python’s greatest feature is how simple it is to understand, even for those who are learning programming from scratch as well as beginners and intermediates. If you are also persistent and consistent, you will have this fantastic programming language under your belt in a matter of weeks.
Indentation to indicate Code Blocks
Python uses indentation to indicate all code blocks. The language strictly enforces this indentation.
The program will not function properly if you indent the incorrect number of spaces. Therefore, when creating codes, you must exercise caution. You can detect a code by using comments to guide you.
The amount of indentation in a level is not defined by the language and can differ from block to block, but each block must be indented by one level in relation to the one before it. The interpreter is happy as long as every block is consistent.
Four spaces are usually used per level by convention. Other conventions include a single tab (people have strong opinions about tabs, either pro or con), two spaces (too little), or eight spaces (too big, in my opinion).
Example
for x in range(20):
if x > 5:
pass # a place holderAs far as where you need to indent, you have to memorize the rules:
Get s v’s stories in your inbox
Join Medium for free to get updates from this writer.
Any statement which is followed by a block requires the block to be indented.
The statement is followed by a colon “:” which helps you recognize that it needs a new block.
The relevant statements include:
class
def
if, elif and else
for and while
try, except and finally
with
match and case
#Important Keywords in Python:
· False,
· class,
· finally,
· is,
· return,
· None,
· continue,
· for,
· lambda,
· try,
· True,
· def,
· from,
· nonlocal,
· while,
· and, del,
· global,
· not,
· with,
· as,
· elif,
· if,
· or,
· yield,
· assert,
· else,
· import,
· pass,
· break,
· except,
· in,
· raise.Variables:
Variables are memory locations that store values and therefore, every time you create a variable, you also reserve a memory for that particular variable.
Data values are stored in variables in Python. They serve as labels or named containers for memory values, enabling you to access and work with them throughout your program.
Important features of Python variables include:
Dynamic Typing: Python does not require you to explicitly declare a variable’s data type, in contrast to certain other languages. The value assigned to it is used to automatically infer the type.
age = 30 # age is an integer
name = "Alice" # name is a string
is_student = True # is_student is a BooleanAssignment Operator (=): The equals sign (=) is used to create variables and assign values to them. The variable name on the left is given the value on the right of the =.
x = 10
message = "Hello, Python!"Mutability: At any stage of the program, variables can be reassigned to different values, including values of different data types.
my_var = 5
my_var = "new value" # my_var now holds a stringNaming guidelines:
Must begin with an underscore (_) or a letter (a-z, A-Z).
Cannot begin with a digit.
May include underscores, numbers, and letters.
Case-sensitive (myVar and myvar are not the same, for example).
Don’t name your variables with Python keywords like if, for, and while.
Referencing Objects: Variables in Python are basically references to memory-based objects. A variable points to the memory location where the data object is stored when you assign a value to it.
# Assigning an integer to a variable
count = 5
# Assigning a string to a variable
greeting = "Welcome!"
# Reassigning a variable to a new value
count = 10
# Assigning multiple variables on one line
a, b, c = 1, 2, 3
# Assigning the same value to multiple variables
x = y = z = 0
print(count)
print(greeting)
print(a, b, c)
print(x, y, z)





