Revision sheet: Python Basics and Math Functions

Course Outline

  1. Printing Text and Output
  2. Built-in Numeric Functions
  3. Math Library Imports
  4. Python Execution Environment
  5. Python Libraries and Applications
  6. Geometry Programming Exercises

1. Printing Text and Output

★ Must-know

  • The print() function displays text, numbers, and evaluated expressions in the program output.

  • Python strings can use single quotes, double quotes, or triple quotes, and triple-quoted strings can span multiple lines.

Further detail

  • The escape sequence \n inserts a line break inside a string.

  • The expression "python"*4 repeats the string four times.

2. Built-in Numeric Functions

Key Concepts & Definitions

  • abs : The built-in function abs() returns the absolute value of a number, such as 4 for abs(-4).
  • pow : The built-in function pow(a,b) calculates the value of aba^b, such as 26=642^6=64.
  • round : The built-in function round(number,digits) rounds a number to the requested number of decimal places, while omitting digits rounds to the nearest integer.
  • ceil and floor : ceil() returns the smallest integer greater than or equal to a number, whereas floor() returns the largest integer less than or equal to it.
  • factorial : Function returns the product of all positive integers from 1 to a given integer, so 5!=1205! = 120.

3. Math Library Imports

★ Must-know

  • import math loads the math module, whose functions and constants are accessed with the math. prefix.

  • from math import factorial, pi, log2 imports selected names so they can be used without the math. prefix.

Further detail

  • import math as M assigns the alias M to the math module, so M.sqrt(25) calls the square-root function through that alias.

  • from math import sqrt as jazr imports sqrt under the local alias jazr, so jazr(25) returns 5.

4. Python Execution Environment

★ Must-know

📌 A compiler processes code as a program before execution, whereas an interpreter processes and executes code line by line.

  • In Visual Studio Code, Python can be run with Run Python File or with Run Without Debugging using Ctrl+F5.

Further detail

  • The integrated terminal can be opened through View → Terminal or with Ctrl+ backtick, and a Python file can be launched with python filename or py filename.

5. Python Libraries and Applications

Key Concepts & Definitions

  • Python library : A collection of ready-made code that provides reusable functions or tools for a particular purpose.

★ Must-know

  • The course identifies pandas for data, NumPy for calculations, Matplotlib for data visualization, scikit-learn for machine learning, and Django for web development.

Further detail

  • The course lists Keras, TensorFlow, and PyTorch in connection with deep learning.

6. Geometry Programming Exercises

★ Must-know

📐 Formula — For a square with side length 55, the perimeter is calculated as P=4×5=20P=4\times5=20 units and the area as A=52=25A=5^2=25 square units.

📐 Formula — For a circle with radius 55, the circumference is calculated as C=2πr=2π×5C=2\pi r=2\pi\times5 and the area as A=πr2=π×52A=\pi r^2=\pi\times5^2.

Further detail

  • The course demonstrates printing a patterned shape with asterisks by placing asterisks and line breaks inside strings passed to print().

Test your knowledge

Test your knowledge on Python Basics and Math Functions with 13 multiple-choice questions with detailed corrections.

1. What does Python display when it executes `print(2+5)`?

2. Which type of Python string can contain line breaks directly within its delimiters?

Take the quiz →

Review with flashcards

Memorize the key concepts of Python Basics and Math Functions with 36 interactive flashcards.

What does the print() function display in Python output?

Text, numbers, and evaluated expressions.

Which quote styles can Python strings use?

Single, double, or triple quotes.

What can triple-quoted strings do that single or double quotes cannot?

Span multiple lines.

See flashcards →

Similar courses

Create your own revision sheets

Import your course and AI generates sheets, quizzes and flashcards in 30 seconds.

Sheet generator