PythonIsCool - Chapter 1
Tags: python, tutorial, beginners, codenewbie
Published: 2022-04-24 16:27:41

# Chapter 1 - Print, Input and Variables

## Table of Contents
[Incorrect Code](#1)
[Syntax Highlighting](#2)
[The Print Function](#3)
[The Input Function](#4)
[Variables](#5)

---

## Incorrect code <a name="1"></a>

To start writing your first line of the code, click the first line of code. Now write whatever you want to write on the line and press run. Luckily for you, if you write a code which doesn't make sense, you will see an error like `SyntaxError : invalid syntax` in red in the console. There are other types of errors like the `UnboundLocalError`, but the most common error right now will the `SyntaxError`.

---

## Syntax Highlighting <a name="2"></a>

Syntax Highlighting is a feature of text editors that make it easier to read the code. So different code parts will have different colours.

---

## The Print Function <a name="3"></a>

The most basic function in Python is `print()`. It is a simple function that just writes whatever is in the brackets in the console. For instance, the way to say `Hello World!` in Python is `print("Hello World!")`. If you write that in code, the output would be `Hello World!`. Have a go at saying `Hello World!` to Python in your code. Try running your code now by pressing the run button. The output should look like the picture below.


![Hello world](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5t54cqe7oonv5puyhv1.png)

If it does, then well done! You have written your first line of proper Python code! If not, compare your code to `print("Hello World!")` and figure out what is wrong.

---

## The Input Function <a name="4"></a>

Input is another common function in Python. It is used to ask the person testing out your code a question. For example, if you want to ask, `How are you?`, you would write, 'input("How are you?")'. The picture in the next page shows how the console would look like after you ran the code. 

![input](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hxsdcxk2fp1fwli1l4i.png)

In the picture above, the code hasn't finished running, as it is still waiting for the user's response to the input.
After you answer the input code, then the line of code is officially finished.

## Variables <a name="5"></a>

Variables are words that have values assigned to them. The values could be numbers, lists, strings, etc. An example of setting a variable is in the code below:

```py
hello = "Hello World!"
```

In the code's case, the variable name is `hello`, and the value is `Hello World!`. Now if you want to show `Hello World!` in the console, you can just set a variable called `hello` with the value of `Hello World!` like above, and then `print(hello)`, bearing in mind that because `hello` is a variable, you don't put speech marks around it.  
Now if you run the code, the result will be the same as the time you wrote the code `print("Hello World!")`. 

Another example of a variable is the code below:
```py
ask = input("How old are you?")
``` 
If you type up that code, the result will be the same as your first input statement. 

As I said, variables can also be numbers, so if you want to assign the variable 'one' the value of the number 1, you will have to do the code below.
```py
one = 1
```
After you copy the code above, if you have copied it correctly, you shouldn't see any errors, and the console should have nothing on it. That is because you haven't called any functions which use the console to display anything.

---

Thanks for reading and I hope you learnt something from this!