Data Types

Theory

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:

  1. Exponentiations are performed from right to left , that is, 3 ** 3 ** 3 is 33^3.
  2. Unary minuses (negations) are performed.
  3. Multiplications and divisions are performed from left to right. Multiplication and division operations have the same priority.
  4. Additions and subtractions are performed from left to right. Addition and subtraction operations have the same priority.

Basic operations on strings:
A + B - concatenation;
A * n - repeat n times, value n must be an integer type.

Problems

Subscribe to receive updates!

Be up-to-date with our recent updates, new problems and answers!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Our courses

Where do you hold your classes?
We hold our classes online or on-site on Saturdays at our branch in Pimlico Academy, London.
You can find our timetable here.
What do you need to start learning online?
For lessons you only need a computer or phone with a microphone, camera and Internet access. Wherever you are - in London, Nottingham, New York or Bali - online lessons will be at hand.
When can I take the introductory lesson?
You can get acquainted with the school at any time convenient for you. To do this, just leave a request and sign up for a lesson.
I can't attend class, what should I do?
It is OK, it happens! Students have the opportunity to cancel a lesson up to 8 hours before the scheduled time without loss of payment. So you can reschedule it for a convenient time, and the teacher will have the opportunity to
I don't have much free time, will I have time to study?
Learning can take place at your own pace. We will select a convenient schedule and at any time we will help you change the schedule, take a break or adjust the program.
How long is one lesson?
All classes last 1 hour.
Hear from some of our amazing students who already achieved incredible results with us!
"Olympiad Maths Lessons helped me a lot to get the Gold medal in Junior Maths Challenge"
St. Paul's Student
"Thanks to the 'Data Science' and 'Coding in Python' lessons I got accepted to my dream university."
Michael
Data Science Student
Warwick University
"Great courses, which thoroughly explained topics beyond the capability of the GCSE answer sheet. Thanks so much."
Ivan
GCSE Student in Dubai
"Financial Mathematics! Best course to understand Python and Mathematics behind Finance!"
Gleb
VC Investor
"We got silver in PMC! Thanks George!"
Mum of St. Paul's Student
Prepare for the Primary Maths Challenge
"My daughter took a batch of 10 classes with George to understand Python with Turtle. I found George extremely knowledgeable and accessible."
Dad of Latymer School Student
Python with Turtle
We’re hiring!

Meet our team

Our teachers will tell you how to prepare for exams, help you cope with difficult tasks and win the Olympiad

They will tell you about the pitfalls of exams and the most common mistakes, and explain how to avoid them
George Ionitsa
Founder &
Teacher of Maths and Coding