30 - Understanding the Basics of Python Programming Flashcards
__ is one of the most common programming languages in the world. It is used by computer programmers and by people in various professions that are interested in automatic and scripting tasks and making their work more efficient.
Python
Why Learn Python?
- Interpreted scripting language
- Low barrier to entry compared to other languages
- Can be used to write various types of Python apps
- Python execution engine exists on most Linux distributions, including network operating systems such as NX-OS
There are two versions of Python currently in widespread use:
- Python 2.x
* Python 3.x
What Python version is this? o No longer under active development, but supported by the Python community o Better library support o Default on Linux and Mac o Supported by Cisco NX-OS
Version 2
What Python version is this? o Under active development o Designed to be easier to learn o Fixed major issues in 2.x o Not backwards compatible
Version 3
What are the two main ways to execute Python code?
- Using the Python dynamic interpreter (shell)
* Writing Python scripts
The Python interactive interpreter, more commonly known as the __, is used to write a test code in real time without having to write a full program or script. The __ is found natively on nearly all Linux distributions and Cisco switch platforms, such as Nexus
Python shell
To open the Python shell, enter the __ command either in a Linux terminal or from the CLI of a Cisco Nexus switch.
python
Python scripts can be written in any text editor and saved locally with the __ file extension. When running a script in this way, the script can be invoked simply by invoking the python statement and the filename.
.py
Which Pyton helper utility returns the python built-in documentation about the object?
Help()
Which Pyton helper utility returns the attributes (and methods) of the object or module?
Dir()
Which Pyton helper utility returns the type of object?
Type()
__ Python programming is concerned with readability and uniformity. There are many things to consider when writing __ Python, often referred to as being Pythonic.
Idiomatic
What are a few things to consider when writing Python to achieve readability and uniformity?
- Single line comments – simply begin the line with the hash # character and the comment automatically terminate at the end of the line
- Multi-line comments – use a delimiter (unique character not in the comment itself) to define the beginning and end of the comment
- Whitespace – characters used for spacing i.e spaces and tabs
- Indentation – leading whitespace at the beginning of the line
- The Python Style Guide (PEP8) – a list of coding conventions for the Python code
Python makes use of many data types:
- Strings
- Numbers
- Lists
- Dictionaries
- Booleans
- Files
__ are simply a sequence of characters that are surrounded by either quotes or double quotes. Without quotes, you are referencing an object. With quotes, it is a __.
Strings
There are two different ways of printing strings:
- Using the print statement to print strings – prints the rendered string
- Typing in the variable name on the Interpreter – prints the value as a string literal
You can add strings together (concatenate) using the __ command.
+
When working with strings, there are functions to modify or verify data within the string. These functions are called __, and there are many __ available.
methods