Python bases in more than 128 words[Partie 2]

This article follows the first part that can be found here:

As with the first article, I'm talking about the basics of the Python language to learn it quickly. In France these bases are taught in high school at the second SNT, first and senior NSI classes. They are also part of the knowledge program for CAPES NSI.

Operators' priority:

I summarize the priority of Python operators, from the highest priority to the lowest priority

  • Parentheses (): Grouping of operations
  • Exhibitor: x 'y'
  • Multiplication, matrix multiplication, division, whole division, modulo: ' , ', /, //, %
  • Addition, subtraction:

Mathematical functions:

import math
  • math.ceil (2.6) upper whole
  • math.floor(-5.3) whole part, gives here -8.0.
  • math.sqrt: square root.
  • math.pow (5, 5): 5 power 5.
  • math.exp(2): exponential function.
  • math.log(2): logarithm function
  • math.log(3, 2): log in base 2.
  • math.factorial(4): factor
  • math.fsum(L): sum of the items on a list
  • math.sin, math.cos, math.tan: trigonometric functions
  • math.pi: pi
  • math.degrees(y): converting radians to degrees
  • math.radians(y): conversion of degrees into radians

Conditional expressions:

Python relies on indentation to define the scope of the code.

x - 100
Y - 23
if x y:
  print ("x bigger than y")
elif a b:
  print ("equality")
  print ("y larger than x")


import math
print (f'The value of pi is 'math.pi:.3f'.')

Two-dimensional lists (matrices):

matrix,[[1, 2, 3] [4,5, 6], [7, 8, 9]]
print (matri[0][1]x)

Methods on the lists:

list.append ('n') #Ajoute an item at the end of the list
list.insert (0,'a') #Ajoute an item at the specified position
list.pop(1) #Enleve the item from the list to the specified position

Leave a Reply

Your email address will not be published. Required fields are marked *