Notes on Python

Complete summary of PYTHON. Features and facts of PYTHON. Brief info on PYTHON identifiers, reserved words, line and indentations, data types and code blocks.

Python is a programming language that is high-level, interpreted, dynamic, and object-oriented. Python is meant to be a very easy – to – understand language. It generally uses English terms rather than punctuation, and it has limited vocabulary structures than other languages.

Among Python’s features are:

  • Easy-to-understand Python features a small number of keywords, a straightforward structure, and a well-defined syntax. This enables the pupil to swiftly learn the language.
  • Easily readable Python code is easier to read and understand since it is more clearly stated.
  • Python’s source code is quite straightforward to maintain.
  • Python has a large standard library that is particularly portable and cross-platform compatible on UNIX, Windows, and Macintosh.
  • Python features an interactive mode that allows interactive testing and debugging of code snippets.
  • Python is portable, meaning it can operate on a broad range of hardware systems and has the same user interface across all of them.

Python Environment Variables:

  • PYTHONPATH
  • PYTHONSTARTUP
  • PYTHONCASEOK
  • PYTHONHOME

Running PYTHON:

There are three methods to get started with Python.

  • Interactive Translator

Python may be run on Unix, DOS, or any other operating system that has a command-line interpreter or shell window.

$python # Unix/Linux

or

python%# Unix/Linux

or

C:> python # Windows/DOS

  • Script to run from the command line

By running the interpreter on your application, you may run a Python script from the command line, as seen below.

$python script.py # Unix/Linux

or

python% script.py # Unix/Linux

or

C: >python script.py # Windows/DOS

  • Integrated Development Environment

You can also run Python from a Graphical User Interface (GUI) environment if you have a GUI programme that supports Python on your system.

Unix- IDLE was the first Unix-based Python IDE.

Python for Windows – PythonWin is the first Python interface for Windows, and it’s an IDE with a graphical user interface.

On the command line, type python.

Python Identifiers:

A Python identifier is a name that is used to identify a variable, function, class, module, or another object in Python. An identifier actually begins with a letter from A to Z, or a to z, or an underscore (_), followed by zero or more letters, underscores, or numbers (0 to 9).

In identifiers, punctuation marks like @, %, and $ are not accepted. Python is a programming language that is case sensitive. As a consequence, in Python, ‘manpower’ and ‘Manpower’ are 2 distinct identifiers.

The naming guidelines for Python identifiers are as follows:

  • The name of the class begins with a capital letter. The commencement of all other identifiers is a lowercase letter.
  • The idea of a single leading underscore in an identifier signifies that it is private.
  • An identification that begins with two leading underscores is considered to be very secret.
  • The identifier is a language-defined special name if it also ends with two trailing underscores.

Reserved Words:

The Python keywords are shown in the table below. You can’t use these terms as constants, variables, or any other identifier names since they’re reserved. Only lowercase characters appear in the Python keywords. Examples- and, exec, assert, break, finally, for, or,  pass, class, from, print, continue, global.

Lines and Indentation:

There are no braces in Python to indicate code blocks for class and function entries or flow control. Line indentation, which is rigorously enforced, is used to denote code blocks.

The indentation could be any number of spaces, however, all statements in the block should be indented the same amount. For instance,

if True:

print “True”

else:

print “false”

The following block, on the other hand, causes an error:

if True:

print “Answer”

print “True”

else:

print “Answer”

print “False”

Data types:

  1. Numbers: Numeric values are stored using the Number data type.
  2. String: The string data type is used to record a character sequence.
  3. Tuple is an immutable data type that is used to hold a collection of multiple data kinds of items.
  4. List: The list data type is mutable and is used to hold a collection of distinct data kinds of components.
  5. Set: The set data type is used to hold a variety of element data types; it is changeable and stores unique elements.
  6. Dictionary: The dictionary data type is used to hold a collection of distinct data kinds of components as key-value pairs. It is changeable and stores a unique key.

Code block:

In Python, a code block is a group of lines of code that are all in the same block or indent. This can be encountered in a variety of places, including classes, functions, and loops.

Because they are 1) on the same indent and

 2) Are not interrupted by other lines of code on the same indent, you can tell where code blocks are.

Python code blocks are useful because they indicate which parts of a loop, class, or function will be executed.

def code_block():

   # Everything in this function is part of the same code block

    print (1)

    print (2)

for i in range (4)

# Everything in this loop is part of the same code block print (i)

Conclusion:

Python is a high-level, robust, open-source programming language that employs simple and easy-to-remember English phrases as its keywords, allowing developers to focus on the solution rather than knowing a huge number of keywords.

It is the most ideal language among others due to its rich library, support for many paradigms, GUI programming features, and integrated features.

faq

Frequently asked questions

Get answers to the most common queries related to the BANK Examination Preparation.

Is it possible to set PYTHONPATH in advance?

Ans. Yes, PYTHONPATH may be set up as a Python installer.

In Python, how do you define tuples?

Ans. In Python, a tuple is a sequence data type. Commas are used to separate the number of values in tuples....Read full

What is the purpose of the Pythonstartup environment variable?

Ans. The Pythonstartup environment variable is used because it specifies the location of the initialization f...Read full

Is there an inherent do-while loop in Python?

Ans. No