CC3-Week-2-Introduction - (Part 1 and 2)

WEEK 2 CC3 - PYTHON PROGRAMMING

  • Instructor: Kim Shaira B. Casimiro

HISTORY OF PYTHON

  • Conceived in the late 1980s, implementation started in December 1989.

  • Creator: Guido van Rossum, developed at the Centre for Mathematics and Computer Science (CWI) in the Netherlands.

  • Designed as a successor to the ABC programming language.

  • Features included exception handling and interfacing with the Amoeba operating system.

  • Guido van Rossum's role: Principal author, continues to direct Python as its "Benevolent Dictator For Life" (BDFL).

THRUST AREAS OF PYTHON

MARKETABILITY OF PYTHON

  • Known for simplicity and developer-friendliness.

  • One of the fastest-growing programming languages; consistently ranked in the top ten since 2003 (TIOBE).

  • As of April 2018, Python ranked 4th in the TIOBE Index.

PYTHON'S RANKINGS

  • 1st by IEEE Spectrum in 2017.

  • 3rd by RedMonk in 2018.

  • Spectrum ranking shows Python outperforming other languages including C, Java, and C++.

ACADEMIA

  • Commonly used as an introductory programming language in American universities.

  • Competes with Matlab for research; advantages include being a true programming language with scientific tools almost equivalent to Matlab modules.

  • Matlab is not considered a real programming language

CORE SCIENTIFIC TOOLS IN PYTHON

  • SciPy: Numerical integration and optimization.

  • NumPy: Provides N-dimensional array objects, linear algebra, Fourier transforms.

  • Jupyter: Changes how programming is done in Python.

  • Tools available under the Berkeley Software Distribution (BSD) license.

HTTP LIBRARY

  • Requests library: Simplifies HTTP operations, supports verbs like GET, POST, PUT, DELETE.

  • Known for thread safety, cookie persistence, and connection timeouts.

MACHINE LEARNING

  • Machine Learning: Effective and adaptive tool to learn from experience and it originates from Computer Science and Statistics.

  • Scikit-Learn - Well-known Machine Learning tool built on top of other
    Python scientific tools like NumPy, SciPy, and Matplotlib

DATABASE CONNECTORS

  • Enable querying from programming languages.

  • Popular open-source databases include MySQL and PostgreSQL.

  • MySQL-Python-Connector is widely used in Python.

OBJECT RELATIONAL MAPPING (ORM)

  • Connects object-oriented programming to relational databases.

  • Popular frameworks: Django (full-fledged) and Flask (microframework).

CLOUD COMPUTING

  • OpenStack: Entirely written in Python for creating clouds, overseen by the OpenStack Foundation.

  • Hosted on platforms like Google App Engine, AWS, Heroku, Microsoft Azure.

GAME DEVELOPMENT

  • Simplifies game development and rapid prototyping via libraries like Pygame.

WHY PYTHON?

  • Cross-platform: works on Windows, Mac, Linux, Raspberry Pi.

  • Syntax similar to English for better readability.

  • Interpreter system allows for immediate execution of code, facilitating faster prototyping.

  • Supports procedural, object-oriented, and functional programming.

PYTHON SYNTAX

GENERAL CHARACTERISTICS

  • Designed for readability; blocks defined using indentation.

  • Uses line breaks, not semicolons or braces, to terminate commands.

INTERPRETED LANGUAGE

  • Source code is converted to bytecode for execution by the Python virtual machine.

  • No need for compiling like in C or C++.

INDENTATION IN PYTHON

  • Critical for defining code scopes and structure; avoids use of symbols or braces.

  • Minimum one space indentation required, consistency is crucial.

COMMENTS IN PYTHON

  • Used to improve code readability and document thought processes.

  • Comments start with # and are ignored by the interpreter.

VARIABLES IN PYTHON

  • Containers for storing data values, created upon assignment.

  • No declaration command is needed; variable types can change dynamically.

EXAMPLES AND TYPES

  • Common data types: int, float, string, char, bool.

  • Example of assignments:

    • number = 5

    • name = "Mary"

STRING HANDLING IN PYTHON

STRING CHARACTERISTICS

  • Strings are sequences of characters with powerful built-in processing capabilities.

  • Declare strings with single or double quotes.

STRING OPERATIONS

CONCATENATION

  • Combining strings using +. Example:

    • print(str0 + " " + str1 + " " + str2).

ACCESSING CHARACTERS

  • Use indexing; negative indices access from the end of the string.

  • Example: mystr = 'I am a String'; print(mystr[-8:]).

STRING FORMATTING

  • Placeholders: format() function or f-strings for dynamic content.

  • Example using format:

    • print("My name is {}".format(name)).

NUMBER FORMATTING FUNCTIONS

COMMON FUNCTIONS

  • round(): Rounds numbers to the nearest whole/decimal place.

  • math.ceil(): Rounds up to the nearest whole number.

  • math.floor(): Rounds down to the nearest integer.

  • pow(): Raises a number to a power.

INPUT AND OUTPUT FUNCTIONS

OUTPUT

  • Use print() to display messages or variable values.

INPUT

  • Capture user input via input(). Example:

    • name = input("Enter Full Name: ").

OPERATORS IN PYTHON

ARITHMETIC OPERATORS

  • Basic operations: +, -, *, /, %, **.

  • Example: x + y.

ASSIGNMENT OPERATORS

  • Assign values to variables: = and compound assignments like +=.

COMPARISON AND LOGICAL OPERATORS

  • Comparison operators like ==, !=, >, and logical operators like and, or, not.

CONTROL STRUCTURES IN PYTHON

TYPES OF CONTROL STRUCTURES

  1. Sequential: Default flow of execution.

  2. Selection: Decision-making using conditional statements.

  3. Iteration: Looping constructs to repeat code.

EXAMPLES

IF STATEMENTS

  • Used to check conditions and branch execution paths.

FOR AND WHILE LOOPS

  • for to iterate over a range, while to repeat actions until a condition fails.

CONCLUSION

  • Questions invited, and wish for continued learning!