Tuesday, February 27, 2024

 Writing your first Python program (Hello World!).


Let's start with some simple code to get a simple output (the information the program gives to the user).

print("Hello World!")

output
Hello World!

You just learned your first command: the print statement. It says "Print out whatever's in my brackets". The print statement is how you get your program to put messages in the console.

  • The " " (quotes) are used to tell the command that you're putting text in there (any text you want)
  • A bunch of text (or whatever you put in quotes) is called a string.

Multiple Print Statements

Here is what multiple print statements looks like. 

print("Well we")
print("just use more lines")
print("of code")

output
Well we
just use more lines
of code


Use the triple quote """ if you want to write a big chunk of text with gaps or line breaks. 

print("""Anything that starts
with three quotes, and ends
in three quotes can span
many lines and even contain " symbols
within it without freaking anything out!""")

Output
Anything that starts
with three quotes, and ends
in three quotes can span
many lines and even contain " symbols
within it without freaking anything out!




 Overview of Python: History and Features


History: Python is a high-level, interpreted programming language created by Guido van Rossum and first released in 1991. The language was designed with an emphasis on simplicity and readability, aiming to provide a clear and concise syntax that promotes code readability and maintainability. Python's development was heavily influenced by other programming languages like ABC, Modula-3, and C.

Key milestones in Python's history include:

  • Python 1.0 (1994): The first official release of Python.
  • Python 2.0 (2000): Introduced list comprehensions, garbage collection, and Unicode support.
  • Python 3.0 (2008): A major revision of the language that introduced backward-incompatible changes to improve clarity and consistency.

Python has since seen widespread adoption in various fields, including web development, data analysis, scientific computing, artificial intelligence, and automation.

Features:

1. Readability: Python's syntax is designed to be clear and easy to read, emphasizing the use of indentation and whitespace to define code blocks, rather than relying on curly braces or keywords.

2. Simplicity: Python prioritizes simplicity and ease of use, making it accessible to beginners while still powerful enough for advanced users. Its minimalist syntax reduces the amount of code needed to express concepts compared to other languages.

3. Dynamically Typed: Python is dynamically typed, meaning variable types are inferred at runtime rather than explicitly declared. This feature allows for more flexibility and rapid development but may require additional testing to catch type-related errors.

4. Interpreted: Python is an interpreted language, which means that code is executed line by line by an interpreter rather than being compiled into machine code beforehand. This makes development and debugging faster but can result in slower execution speed compared to compiled languages.

5. High-level: Python provides built-in data structures and abstractions that simplify programming tasks, allowing developers to focus on solving problems rather than managing memory or low-level details.

6. Object-oriented: Python supports object-oriented programming (OOP) principles, including encapsulation, inheritance, and polymorphism. Everything in Python is an object, making it easy to organize and manipulate code into reusable components.

7. Extensive Standard Library: Python comes with a comprehensive standard library that includes modules and functions for performing common tasks such as file I/O, networking, regular expressions, and more. This library reduces the need for external dependencies and facilitates rapid development.

8. Cross-platform: Python is platform-independent, meaning that Python code can run on various operating systems without modification. This portability makes it an ideal choice for developing cross-platform applications.

Overall, Python's combination of simplicity, readability, and versatility has made it one of the most popular programming languages worldwide, used by developers in a wide range of industries and domains.

  2D Dictionaries Remember that dictionaries are very similar to lists, except that they store data as key:value pairs. The value is what it...