So, we see that Python can work with at least two types of data - numbers and strings. Numbers are written as a sequence of digits; there may also be a minus sign in front of the number, and strings are written in single quotes. 2 and '2' are different objects, the first object is a number and the second is a string. The + operation works differently for integers and for strings: for numbers it is addition, and for strings it is concatenation.
In addition to integers, there is another class of numbers: real numbers, represented as decimal fractions. They are written using a decimal point, for example 2.0. In a sense, 2 and 2.0 have equal meaning, but they are different objects. For example, you can evaluate the expression 'ABC' * 10 (repeat the string 10 times), but you cannot evaluate 'ABC' * 10.0.
You can determine the type of an object using the type function:
>>> type(2)
<class 'int'>
>>> type('2')
<class 'str'>
>>> type(2.0)
<class 'float'>
Please note type() is a function, the function's arguments are given in parentheses after its name.
Here is a list of basic operations for numbers:
A + B - sum;
A - B - difference;
A * B - product;
A/B - private;
A**B - exponentiation.
It's useful to remember that the square root of x is x**0.5, and the root of n is x**(1/n).
There is also a unary version of the operation -, that is, an operation with one argument. It returns the opposite number of the given one. For example: -A.
An expression can contain many operations in a row. How is the order of action determined in this case? For example, what would 1 + 2 * 3 ** 1 + 1 be equal to? In this case, the answer will be 8, since the exponentiation is performed first, then the multiplication, then the addition.
More general rules for determining the priorities of operations are as follows:
Basic operations on strings:
A + B - concatenation;
A * n - repeat n times, value n must be an integer type.
Be up-to-date with our recent updates, new problems and answers!
Our goal at this course is to enhance our students’ mathematical intuition by focusing on a deep understanding of mathematical concepts and to enable them to link different concepts and apply their knowledge to solve mathematical problems to help them to improve their performance at Maths exams.
This course guides you through the fundamentals of Python programming using an interactive Python library known as Turtle.
This course encompasses a range of Geometry topics such as coordinate and spatial geometry, introductory trigonometry, angles, parallel lines, congruent and similar triangles, polygons, circles, the Pythagorean Theorem, and more. Emphasis will be placed on reinforcing Algebra skills and enhancing critical thinking through problem-solving in both mathematical and real-world contexts.