Foreword
Good day, Habr. I'm launching a short article course that covers the key Python skills required to learn Data Science. These articles are suitable for those who already had programming experience and want to add Python to their skill set.
Hello Python!
Python was named after the popular 1970s British comedy TV show Monty Python's Flying Circus, as the author was a fan of the TV show.
Just for fun, try reading the code below and predicting what it will do on startup. (If you don't know, that's ok!) It is timed to a sketch of Monty Python about spam.
spam_amount = 0
print(spam_amount)
# , , , , ( 4 )
spam_amount = spam_amount + 4
if spam_amount > 0:
print("But I don't want ANY spam!")
viking_song = "Spam " * spam_amount
print(viking_song)
Output
0
But I don`t want ANY spam!
Spam Spam Spam Spam
, Python . .
spam_amount = 0
: spam_amount 0 =
, .
: (, Java C ++), , Python :
โข
spam_amount
โข Python,
spam_amount
. ,spam_amount
, .
print(spam_amount)
: print
- Python, . , ( ) .
# , , , , ( 4 )
spam_amount = spam_amount + 4
- . Python #
.
. , - - =
.
, spam_amount
, . , Python =
(0 + 4 = 4), .
if spam_amount > 0:
print("But I don't want ANY spam!")
viking_song = "Spam Spam Spam"
print(viking_song)
ยซ ยป , , , , , , . Python .
, , if
. "But I don't want ANY spam! "
, spam_amount
. (, print (viking_song)
) . ( Python) ?
(:
) if
, ยซ ยป. . {
}
. Python , , , , .
, viking_song
, 4 , if
. , .
โโPython:
"But I don't want ANY spam!"
. ( , Python, , .)
viking_song = "Spam " * spam_amount
print(viking_song)
*
(3 * 3
9), , , , , . Python , , *
+
, . ( - )
Python
, :
spam_amount = 0
ยซยป - , , Python, , spam_amount
:
type(spam_amount)
int
int
- integer. , Python:
type(19.95)
float
float
- , , .
type()
- , ( print()
), . Python ยซ ?ยป.
- . +
*
. Python :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, , , , , Python . ยซ ยป - , :
print(5 / 2)
print(6 / 2)
2.5
3.0
float
.
//
, .
print(5 // 2)
print(6 // 2)
2
3
, ?
, , , . , PEMDAS - , , /, / (Parentheses, Exponents, Multiplication/Division, Addition/Subtraction).
Python , . .
8 - 3 + 2
7
-3 + 4 * 2
5
:
hat_height_cm = 25
my_height_cm = 190
# ?
total_height_meters = hat_height_cm + my_height_cm / 100
print("Height in meters =", total_height_meters, "?")
Height in meters = 26.9 ?
. , Python .
total_height_meters = (hat_height_cm + my_height_cm) / 100
print("Height in meters =", total_height_meters)
Height in meters = 2.15
Built-in functions for working with numbers
Functions min
and max
return the minimum and maximum of their arguments, respectively:
print(min(1, 2, 3))
print(max(1, 2, 3))
1
3
The function abs
returns the absolute value of its argument:
print(abs(32))
print(abs(-32))
32
32
In addition to the names of the two main numeric types in Python, int
and float
can also be called as functions that convert their arguments to the appropriate type:
print(float(10))
print(int(3.33))
#
print(int('807') + 1)
10.0
3
808
Afterword
With this the first article came to an end. Thanks to everyone who read and took the time. I also hope that you have learned some useful information and learned something new. Continue to develop and learn new things! See you soon.