# Basic Syntax

## "Hello, World!" Program

This is the typical first program for those new to a general purpose programming language like Python. It can be used to test that the [**Installation**](https://docs.bcbi.brown.edu/codiac-for-health/computing/python/installation) of Python is working and also introduce Python's basic syntax using the [**REPL**](https://docs.bcbi.brown.edu/codiac-for-health/computing/python/repl) environment or running code written using a [**Text Editor**](https://docs.bcbi.brown.edu/codiac-for-health/computing/text-editors) at the [**Unix**](https://docs.bcbi.brown.edu/codiac-for-health/computing/unix) command line.

Input:

```python
# hello.py
# This is a single line comment 
'''
This is a block comment to show 
comments across multiple lines.
'''

print("Hello, World!")
```

Output:

```
Hello, World!
```

Here are variations of the "Hello, World!" programming using variables and different print statements.

Input:

```python
# hello2.py

greeting = "Hello, World!"

print(greeting) # print greeting
print(f"Greeting 1: {greeting}") # print greeting as part of a string phrase
print(f"Greeting 2: {greeting}\n") # print with newline (\n) character
```

Output:&#x20;

```
Hello, World!
Greeting 1: Hello, World!
Greeting 2: Hello, World!
```

## Variable Assignment

In order to assign variables in Python, you write the desired name for your variable, an “=” sign, and what the value of the variable should be.

Input:

```python
x = 7
x
```

Output:

```python
7
```

## Comments

* We can write comments on our code, which do not run, to describe what certain lines of code or section of code do
  * These comments are just for the programmer, they will not appear anywhere in the output and just are there to explain what the code is doing or to provide helpful notes
  * To make a comment in Python, you can use the “#” symbol and then type your comment&#x20;
* Sometimes you might want to write longer comments that span multiple lines – to do this you can surround these comments with three tick marks above the start as well as three tick marks below the end

Input:

```python
# Assigns variable x to have value 7
x = 7

'''
Now we want to print out what x is. We can do this by simply typing x and 
hitting run. This comment spans multiple lines. These types of comments are 
useful when describing complex functions or algorithms.
'''

x

```

Output:

```python
7
```

## Print Statements

Without using a print statement, Python will only print out the most recent item that has an output. In order to print multiple things, we can use the print() function&#x20;

Input:

```python
# Assign x, y, and z variables 
x = 7
y = 10
z = 4

z
print(x)
print(y)
```

Output:

```python
7
10
```

## Indentation

Python is very sensitive with its indentation notation. Indentation should only be used in hierarchical structures, such as a class, function, or loop. Indents in improper locations will cause an error

Input:

```python
# Assign x and y variables 

x = 7
    y = 10
    
print(x)
print(y)
```

Output:

```python
IndentationError: unexpected indent
```

## Exercises

* Use Python in Brown Oscar Computing Environment - *<mark style="color:yellow;">Forthcoming!</mark>*
* Use Python in Brown Stronghold Computing Environment - *<mark style="color:yellow;">Forthcoming!</mark>*

## Resources

* Real Python: [Variables](https://realpython.com/python-variables/)
* W3 Schools: [Comments](https://www.w3schools.com/python/python_comments.asp)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bcbi.brown.edu/codiac-for-health/computing/python/basic-syntax.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
