[go: up one dir, main page]

0% found this document useful (0 votes)
38 views8 pages

Execute Python Syntax

TT 4

Uploaded by

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

Execute Python Syntax

TT 4

Uploaded by

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

 Menu  Log in

  HTML CSS   

Python Syntax
❮ Previous Next ❯

Execute Python Syntax On this page

As we learned in the previous page, Python syntax can


Execute Python Syntax
be executed by writing directly in the Command Line:
Python Indentation

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

Hello, World! Python Comments

Exercises

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.

Example

if 5 > 2:

 
print("Five is greater than two!")

Try it Yourself »

Python will give you an error if you skip the indentation:

Example
Syntax Error:

if 5 > 2:

print("Five is greater than two!")

Try it Yourself »

The number of spaces is up to you as a programmer, but it has to be at least one.

Example

if 5 > 2:

 print("Five is greater than two!") 

if 5 > 2:

        print("Five is greater than two!") 


Try it Yourself »

You have to use the same number of spaces in the same block of code, otherwise Python
will give you an error:

Example
Syntax Error:

if 5 > 2:

 print("Five is greater than two!")

        print("Five is greater than two!")

Try it Yourself »

Python Variables
In Python, variables are created when you assign a value to it:

Example
Variables in Python:

x = 5

y = "Hello, World!"

Try it Yourself »

Python has no command for declaring a variable.

You will learn more about variables in the Python Variables chapter.
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!")

Try it Yourself »

Test Yourself With Exercises

Exercise:
Insert the missing part of the code below to output "Hello World".

("Hello World")

Submit Answer »

Start the Exercise


❮ Previous Next ❯

NEW

We just launched

W3Schools videos

Explore now

COLOR PICKER




Get certified

by completing

a course today!
school
w3 s

2
CE

02
TI 2

R
FI .
ED

Get started

CODE GAME

Play Game

Report Error

Forum

About

Shop
Top Tutorials
HTML Tutorial

CSS Tutorial

JavaScript Tutorial

How To Tutorial

SQL Tutorial

Python Tutorial

W3.CSS Tutorial

Bootstrap Tutorial

PHP Tutorial

Java Tutorial

C++ Tutorial

jQuery Tutorial

Top References
HTML Reference

CSS Reference

JavaScript Reference

SQL Reference

Python Reference

W3.CSS Reference

Bootstrap Reference

PHP Reference

HTML Colors

Java Reference

Angular Reference

jQuery Reference

Top Examples
HTML Examples

CSS Examples

JavaScript Examples

How To Examples

SQL Examples

Python Examples

W3.CSS Examples

Bootstrap Examples

PHP Examples

Java Examples

XML Examples

jQuery Examples

Web Courses
HTML Course

CSS Course

JavaScript Course

Front End Course

SQL Course

Python Course

PHP Course

jQuery Course

Java Course

C++ Course
C# Course

XML Course

Get Certified »

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant
full correctness of all content.
While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.

Copyright 1999-2022 by Refsnes Data. All Rights Reserved.

W3Schools is Powered by W3.CSS.

You might also like