Python Intro - The Mechanics Flashcards
Understand why organized files are required for Python code success
Where is Python code most commonly used?
Python code is commonly used to connect web applications, like the web pages you see (the “frontend”), with the behind-the-scenes database and computer logic (the “backend”) that users don’t see.
What is the name of the technology that allows Python to connect with a webpage?
Web Server Gateway Interface (WSGI) is a standard developed for Python that defines how web applications (the “frontend”) communicate with Python web applications on the server (the “backend”).
WSGI serves as a bridge, managing the communication between web server software (like Apache or Nginx) and Python applications and development frameworks, ensuring smooth data exchange.
What major websites have been built using Python code?
Some of the biggest names that utilize Python include Google, YouTube, Instagram, Pinterest, Reddit, Netflix, Spotify, Uber, Dropbox, Quora, Instacart, and Bitly.
Describe website applications that might be driven by Python?
While it’s not always visible from the outside, Python-driven applications often handle complex tasks such as:
Managing e-commerce platforms.
Powering social networking platforms.
Operating web portals like Google, Yahoo, and MSN.
Running Web APIs, which are custom applications that link different services, enabling the functionality of services like Google Maps, Spotify, and Facebook (now Meta).
Name at least five examples of Python projects (applications).
- Data storage and retrieval systems.
- User authentication and authorization processes.
- Content management tools.
- E-commerce platforms.
- API development, enabling websites to interact and share data with each other.
On the web, what do “backend” and “frontend” mean?
The backend, or server-side, is where coding and data processing happen on web servers—this part supports and delivers content to the web but is not directly seen by users.
The frontend refers to everything that users interact with directly, such as websites’ layouts, design, and interactions, essentially the user interface layer.
Which frontend technologies used for developing webpage displays can be supported by Python applications?
While Python itself is used on the backend, it can integrate with frontend technologies like HTML (HyperText Markup Language), CSS (Cascading Style Sheets), and JavaScript.
These technologies shape the webpage displays that users see and interact with, while Python handles server-side (backend) logic, data processing, and communication with the frontend.
What apps are used to design attractive webpages?
Python itself is not typically used for designing the visual aspects of webpages.
Front-end design, which includes layouts, graphics, and interactive elements, is primarily handled by technologies like HTML, CSS, and JavaScript or through website builders like Wix, Squarespace, or GoDaddy.
Python, however, is essential for backend tasks such as managing interactivity and data processing.
What is bytecode in the context of Python programming?
Bytecode is a set of instructions for computers that is not quite as simple as the 0s and 1s which the computer’s main processor uses (known as “machine code”), but also not as complex as the full written code a human programmer creates (like Python code).
Think of bytecode being a middle ground — it’s prepared and simplified so computers can understand it quickly.
Why do computers use bytecode?
Computers use bytecode because it balances two important needs:
- It makes the code able to run on different kinds of devices (like PCs, tablets, or servers)
- It allows the code to run quickly.
When programming languages like Python are used, the written code gets turned into bytecode, which then gets translated into the actions the computer performs, regardless of the type of device.
Describe Python as an interpreted computer language.
Python is an interpreted language, which interprets and runs the code line by line, directly translating human-readable code into a special kind of computer instructions called bytecode.
This is unlike traditional compiled languages, which first transforms code into a specific format that can only run on certain types of computers or operating systems.
Python can run on any device that has a Python interpreter, making it widely usable. Once a Python program runs for the first time when it is compiled into bytecode, it will run faster in subsequent uses.
Python only recompiles the source code into bytecode when changes are made to the code.
As an interpreted language, why is Python important to web development?
Compiled code, such as C, C++, or Java run on specific computer operating systems. They are not platform independent.
As an interpreted language, Python is not compiled into machine code, therefore making its platform independent and the files that contain the programs small.
Python can be run on any operating system, enabling website development to be accessible to developers everywhere.
Describe how Python code is written.
Python code is composed using a programming language that resembles English. Developers write instructions line by line, with each line representing a distinct statement or task.
These instructions—or ‘statements’—collectively define how the program operates, with each one building upon or complementing the others to perform complex functions.
Can Python code be written in languages other than English?
Python’s syntax and reserved keywords are in English, but developers can write comments and name variables using any Unicode-supported language.
This allows speakers of different languages to document and develop with Python in a way that’s more familiar to them while adhering to the language’s English-based syntax for the programming logic.
Describe how .py files are formatted.
Python files are saved with the .py file extension and contain source code written in plain text using the Unicode standard.
This ensures that Python code can include characters from virtually any written language, making the code universally readable on systems that support Unicode.
Who oversees Unicode standards?
The Unicode Consortium, a non-profit organization, is responsible for maintaining the Unicode Standard.
Their work ensures that each written character and symbol from the world’s various language systems has a unique identifier, enabling consistent representation and accessibility across different digital platforms, software, and devices. This universality allows for the exchange and display of text in any language reliably.
Can any word processing program be used to write Python code to file?
It’s best to use a plain text editor that supports Unicode to write Python code, as word processors often include formatting and special characters incompatible with Python.
Saving code with these extra elements can cause errors, like the UnicodeDecodeError, when you try to run the script.
Notepad, Visual Studio Code, and Sublime Text are examples of editors suitable for writing clean .py files.
Describe why using an IDE best supports the development of Python code.
While Python code can be written in basic text editors that support Unicode, Integrated Development Environments (IDEs) offer many advanced features that aid in writing and debugging code.
IDEs frequently come with code completion, error highlighting, integrated version control, and debugging tools, among other helpful features most text editors lack.
This makes Python development faster, easier, and less prone to mistakes. Popular IDEs for Python include PyCharm, Anaconda Navigator, and Visual Studio Code.
Identify 5 filename suffixes associated with Python and what they represent.
.py: Standard Python source code file or module.
.pyc: Compiled Python file containing bytecode, which is generated after a .py file is run.
.pyo: An optimized bytecode file used in older versions of Python, removed in Python 3.5.
.pyd: A Python Dynamic Module, similar to a Windows DLL file, used to call functions from a compiled C or C++ library.
.so or .dylib: These are shared object files on Unix-like systems (Linux, macOS) used similarly to .pyd files on Windows, allowing Python to use compiled code from other languages.
The updates made to the .pyo entry reflect the actual Python version in which it was removed.
Additionally, the .so and .dylib are clarified to match typical usage on Unix-like operating systems.
Where are Python system files stored on a computer drive?
On a personal computer, the location of Python system files depends on the operating system and how Python was installed. Typically:
On Windows, you might find them in C:\Users\UserName\AppData\Local\Programs\Python\Python<version></version>
On macOS, often in /Library/Frameworks/Python.framework/Versions/<version></version>
On Linux, typically in /usr/bin/python<version> or /usr/local/bin/python<version> In shared environments or on the cloud, the system administrator decides the storage location.</version></version>
For precise installation locations and versions, consult the official Python website at www.python.org, particularly under ‘Downloads’ and ‘Documentation.’
Where are Python bytcode files saved once they are created?
When a Python .py file is run, it’s compiled into bytecode and saved as a .pyc file.
These .pyc files are stored in a directory (folder) named __pycache__, located in the same directory as the source .py file.
The Python interpreter will use the .pyc files for execution to save time unless the source .py file has been modified, which triggers recompilation.
This check is done through comparison of the .pyc file’s timestamp with that of the corresponding .py file.