0% found this document useful (0 votes)
8 views4 pages

Previous Next : Your Name

This document provides a beginner's guide to getting started with Python, including installation instructions and basic syntax. It explains how to check for Python installation, create and run a simple Python script, and the importance of indentation and comments in Python code. Additionally, it covers how to create single-line and multiline comments for documentation purposes.

Uploaded by

Priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Previous Next : Your Name

This document provides a beginner's guide to getting started with Python, including installation instructions and basic syntax. It explains how to check for Python installation, create and run a simple Python script, and the importance of indentation and comments in Python code. Additionally, it covers how to create single-line and multiline comments for documentation purposes.

Uploaded by

Priyanka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Getting Started

❮ PreviousNext ❯

Python Install

Many PCs and Macs will have python already installed.

To check if you have python installed on a Windows PC, search in the start
bar for Python or run the following on the Command Line (cmd.exe):

C:\Users\Your Name>python --version

To check if you have python installed on a Linux or Mac, then on linux


open the command line or on Mac open the Terminal and type:

python --version

If you find that you do not have Python installed on your computer, then
you can download it for free from the following
website: https://www.python.org/

Python Quickstart

Python is an interpreted programming language, this means that as a


developer you write Python (.py) files in a text editor and then put those
files into the python interpreter to be executed.

The way to run a python file is like this on the command line:

C:\Users\Your Name>python helloworld.py

Where "helloworld.py" is the name of your python file.

Let's write our first Python file, called helloworld.py, which can be done in
any text editor.

helloworld.py

print("Hello, World!")

Simple as that. Save your file. Open your command line, navigate to the
directory where you saved your file, and run:

C:\Users\Your Name>python helloworld.py

The output should read:

Hello, World!

Execute Python Syntax


As we learned in the previous page, Python syntax can be executed by
writing directly in the Command Line:

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


Hello, World!

On this page

Execute Python SyntaxPython IndentationPython VariablesPython


CommentsExercises

Or by creating a python file on the server, using the .py file extension, and
running it in the Command Line:

C:\Users\Your Name>python myfile.py

Python Indentation

Indentation refers to the spaces at the beginning of a code line.

Where in other programming languages the indentation in code is for


readability only, the indentation in Python is very important.

Python uses indentation to indicate a block of code.

ExampleGet your own Python Server

if 5 > 2:
print("Five is greater than two!")

Comments

Python has commenting capability for the purpose of in-code


documentation.

Comments start with a #, and Python will render the rest of the line as a
comment:

Example

Comments in Python:

#This is a comment.
print("Hello, World!")

Python Comments

❮ PreviousNext ❯

Comments can be used to explain Python code.


Comments can be used to make the code more readable.

Comments can be used to prevent execution when testing code.

Creating a Comment

Comments starts with a #, and Python will ignore them:

ExampleGet your own Python Server

#This is a comment
print("Hello, World!")

Try it Yourself »

Comments can be placed at the end of a line, and Python will ignore the
rest of the line:

Example

print("Hello, World!") #This is a comment

Try it Yourself »

A comment does not have to be text that explains the code, it can also be
used to prevent Python from executing code:

Example

#print("Hello, World!")
print("Cheers, Mate!")

Try it Yourself »

ADVERTISEMENT

Multiline Comments

Python does not really have a syntax for multiline comments.

To add a multiline comment you could insert a # for each line:

Example

#This is a comment
#written in
#more than just one line
print("Hello, World!")
Try it Yourself »

Or, not quite as intended, you can use a multiline string.

Since Python will ignore string literals that are not assigned to a variable,
you can add a multiline string (triple quotes) in your code, and place your
comment inside it:

Example

"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")

Try it Yourself »

As long as the string is not assigned to a variable, Python will read the
code, but then ignore it, and you have made a multiline comment.

Exercise?

Which character is used to define a Python comment:

'

//

/*

Submit Answer »

Video: Python Comments

You might also like