Roman Gurbanov - Python Handbook For Beginners

Здесь есть возможность читать онлайн «Roman Gurbanov - Python Handbook For Beginners» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Год выпуска: 2021, ISBN: 2021, Жанр: Технические науки, Программирование, на русском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Python Handbook For Beginners: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Python Handbook For Beginners»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This book will provide you with basic knowledge and skills in Python programming, covering topics such as variables, numbers, strings, booleans, conditional statements, loops, lists, dictionaries, functions, classes and objects, modules, and packages.
Every chapter is wrapped up with a small test. Detailed explanations and practical examples accompany every topic to ensure you acquire an essential Python coding skill upon completing the book.
This book is excellent for everyone who wants to learn to code and is just starting. Other great books are available for those who have already mastered basic Python programming skills and looking to improve them.

Python Handbook For Beginners — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Python Handbook For Beginners», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

3) Computers use variables to retrieve or delete information.

2. If a variable name consists of two or more words, you shall connect them using:

1) Underscore.

2) Dash line.

3) Write the words together, without space.

4) Write the words together with a capital letter without space.

3. We can display a variable on the screen by:

1) Using the print() function and passing the print command in its parentheses.

2) Using the print() function and passing the value of the variable in its parentheses.

3) Using the print() function and passing the name of the variable in its parentheses.

4. Arrange the parts of the code so that the program creates and displays the variable.

(name)

name

=

print

"John Doe"

CHAPTER THREE: NUMBERS

1 Integers and Fractional Numbers

You already know that integers, like 5 or 10, and fractional numbers, like 5.5 or 10.7, also called float from your school math classes. Python works with both types of numbers. It also works with relevant math operators, which are coming further.

2 Math operators

Python allows you to work with numbers using relevant math operators, that are:

1) Addition operator: +

2) Subtraction operator: -

3) Multiplication operator: *

4) Division operator: /

Let's jump into the console to work with some numbers and math operators.

3 Working with Numbers

Run empty console and hit repl button, which you already know. You should get an empty input field: input 2+2, and hit enter. What's the number you've got? Now, using the same field, subtract 5 out of 10, using subtraction operator: – Let's also multiply 5 by 5, using the multiplication operator: * Finally, let's divide 10 by 2, using the division operator: /

4 Division Without Remainder

Let's talk about division without remainder in Python. Did you notice that we've got a fraction when we divided 10 by 2, which was 5.0? But what if we need to get an integer? To get that, all we need is to use a double division operator – // Try it out. Open the input field, write 10//2, and hit enter. What number have you got now?

5 Calculation Order

Python handles calculation order, which has no difference from the order you've learned in math classes. Can you calculate (5+5)*3, then write it into the input field and check if you were right? Here is how Python will calculate it:

First, Python will calculate whatever is in brackets, following the order: first multiplication, then division, then addition, then subtraction. After that, Python will calculate whatever is around brackets, following the same order as above (multiplication, division, addition, subtraction)

Hence, Python will add 5 and 5, which will result in 10. And multiply 10 by 3, which will result in 30. Was your answer – 30? Or was it something else?)

6 Numbers and Variables

By this time, we've learned print function, variables, and numbers in Python. Let's combine them all!

Let's write an example with numbers, save its result in a variable, and then display it. Here is how it looks like:

result = 2+2

print(result)

Guess what the output will be? Please take the above code and run it in the console to check it out.

Let's break it down:

1) First, we declared a variable, giving it the name "result" and the value "1 + 1";

2) Then we went down one line, wrote the print function, and passed the name of our variable in its brackets;

3) When we ran the code, Python calculated the value of the variable by adding 2 + 2;

4) The calculation returned 4, and Python assigned this value to the variable "result";

5) Then Python saw that we want to display the result's value because of the print (result) and print it accordingly.

As you can see, numbers and variables work well together in Python.

Let's practice some more and create your examples with numbers and variables, similar to what we just saw. Here are some boilerplate examples for you:

___________

result = 2+2

print(result)

___________

result = 10-5

print(result)

___________

result = 5*5

print(result)

___________

result = 10/2

print(result)

___________

7 Wrapping Up Chapter Three

In chapter three, we have accomplished the following:

1) Refreshed on what are integers and fractional numbers;

2) Learned basic math operators used in Python;

3) Learned how to divide a number without remainder in Python;

4) Got to know the order of calculation in Python;

5) Combined numbers and variables in math examples.

8 Chapter Three Test

1. What types of numbers are there in Python?

1) There are three types of numbers in Python: Integers, almost whole numbers, and fractional.

2) There are two types of numbers in Python: Integers and half integers.

3) There are two types of numbers in Python: Integers – integer and fractional numbers.

2. How does Python divide 10 by 5? (Multiple selection)

1) 10:5

2) 10/5

3) 10-5

4) 10 * 5

5) 10 // 5

3. Arrange the parts of the code so that you get the integer 4.

five

10*2

//

4. This code should display 5. But what is missing?

result = 10/2

_____(result)

CHAPTER FOUR: STRINGS

1 Strings in Python

Do you remember the messages we displayed in chapter one, like "Hey! This is my first line of code!" or "Once upon a time.." They are all strings. In other words, a string is a data type that has a text format, or just a text, enclosed in quotes. Hence, to create a string, we have to type a text and enclose it in quotes.

2 Strings And Print Function

Let's write a code that would display the string – "Now I know what a string is in Python." You already know how to display strings in Python, right? Here is the code.

print("Now I know what a string is in Python.")

Write the above line into the console and hit run. Now it's your turn. Think of some different string, rewrite and run the above code.

3 Saving Strings in Variables

Do you remember our first variable: film = "Super Cat"? Now you know that the value of the variable – "Super Cat" had a string format, as we enclose it in quotes. Let's take our knowledge further, create a message in a string format, save it in a variable, and display the variable value on your screen using the print function. Let me do it first:

message = "Hello, Super Cat!"

print(message)

Run this code in the console. What do you see? Now it's your turn. Following the above example, think of any message. Right it down as a string. Save it in a variable and display the variable value using the print function. What you've got?

4 Strings Concatenation

We can combine strings. There is a method for that, called – concatenation. All we have to do to concatenate strings is to put addition operator + between them. Easy right? If so, let's get concatenating!

"Super Cat" + "saves the day!"

Now, let's display the two concatenated strings:

print("Super Cat" + "saves the day!")

Write this code into the console and hit run. Have you noticed something weird? Hmm. It looks like our lines stuck together. No worries. We can quickly fix that. There are several ways to do it but let's stick with the most simple – leave a space between the quote and string:

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Python Handbook For Beginners»

Представляем Вашему вниманию похожие книги на «Python Handbook For Beginners» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Python Handbook For Beginners»

Обсуждение, отзывы о книге «Python Handbook For Beginners» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x