Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 1.32 KB

hello.md

File metadata and controls

84 lines (58 loc) · 1.32 KB

Hello World

print("Hello World!")

Output:

Hello World!

Words, characters, text are called strings. They must be surrounded with single quotes ( ' ) or double quotes ( " ). They can be joined together with the + (plus) operator:

print("Hello" + "World!")

Output:

HelloWorld!

Notice: The space between the two words is missing. We did not include it! We can add it like this:

print("Hello" + " " + "World!")

Or like this:

print("Hello " + "World!")
#           ^ Here is the space

Output:

Hello World!

We can also print numbers!

print(1)
print(123)

But numbers behave differently than strings. This is called a data type. We'll talk more about data types later. For example:

print(1 + 1)

Output:

2

print("1" + "1")

Output:

11

Trying to add a number to a string will result in an error:

print(1 + "1")

Output:

TypeError: unsupported operand type(s) for +: 'int' and 'str'

We can view the type of any object using the type() function:

print(type(1))

Output:

<class 'int'>

print(type("1"))

Output:

<class 'str'>

As we can see, a data type of "number" in Python is called int (short for integer) and a data type of "string" is called str (short for string).