I'm Your Python !

[Eng] 2. print( ) Function / Basic Data Types in Python

HappyPudding 2021. 8. 15. 05:16

In the last post, we covered about the meaning of program and the way to run Python.
From now on, we will see about the functions of Python, one by one : )

As I told you guys, I will explain it from the basic, especially for non-majors and true beginners !


(1) print( ) function

① print( ): printing something on console, and doing line-break(the function of Enter key)
: Between the ( ), you can enter the thing you want to print.
And this function is not only printing somethig, but also doing line-breaking.

You can understand it easily by the image below.

By writing print("Hello") and clicking the 'run' button, you can simply prints 'Hello' out to the console.
And you can see the empty space below the 'Hello'.
It is because the print( ) function includes the function of Enter key.

If you don't want to do line-break, you can simply add this. → end=" " .


② print(something, end=" ")


Like this, by adding an 'end=" "' after the thing you want to print, you can easily delete the function of Enter Key.

Also, if you write something between " ", like print("Hello", end="World"), it is printed in a row like HelloWorld.

(2) The Basic Data Types in Python

There are many of data types in Python, but the underlying ones are 'String', 'Integer', and 'Float'.

① String
: Generally, one character is called 'char' and more than two of them are called 'string'.
But in Python, there are no big difference between them.
So we can call all of them as a 'string'.

We must use " " when we write a string, like print("Hello").
And then when you run it, the " " is disappeared, so just Hello is printed.
(Just string is printed, with no " " )

② Integer
: Integer doesn't need " ", so you should enter only number.
In the computer science, Integer means the number without decimal, like 10, 314, 268.
And it is apparently distinct from float.

ex) print(314), print(268)

③ Float
: Like Integer, it doesn't need " ", but it means the number with decimal, like 3.14, 2.68.

ex) print(3.14), print(2.68)


And then, what's the difference between print("3.14") and print(3.14) ?
→ The former means string '3, ., 1, 4' and the latter meants the float(nember) 3.14 .
If these are ran, the output are same on console, but the meanings are definitely different.


#Tip) How to Interlink outputs? - When you want to print somethings in a row.

→ You can simply put ' , ' between them!
print("My Math Score =", 55) illustrates it.
If you run it, My Math Score = 55 is printed.