Sitemap

Python From Scratch

Syntax

4 min readAug 10, 2020

--

Chapter-3

In my first post, I have already shared a link for downloading python ,once installed, you can confirm it by typing python in Windows search option.

Press enter or click to view image in full size

You can also verify the same using command Prompt as shown below:

Press enter or click to view image in full size

As we are done with installation and setup, now we will look at Syntax Structure of Python.

The term Syntax is referred to a set of rules that describes the structure of a language. The Python syntax defines all the set of rules that are used to create sentences in Python programming. eg. As basically grammar is important in English exactly the same way Syntaxes are important in programming languages.

Types of Syntax Structure in Python :

Press enter or click to view image in full size

Line Structure:Python Comprises of logical lines so each line must be closed at correct point.Some examples are here to show how important line structure is:

Press enter or click to view image in full size

Docstrings : Docstrings means documentation string. It is basically used for giving the precise description about the code. Docstrings are defined using 3 double quote Syntax.

docstring

Quotations:Python supports single and double quotes for string literals but the only thing we have to keep in mind is ,If we starts string with using single quote then we must end the string using single quote only ,similar is with double quote.

Variables:A Python Variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing.In Python, we don’t define the type of the variable. It is assumed on the basis of the value it holds.

Press enter or click to view image in full size
Variables

Comments : ‘Comments’ lets us store tags at the right places in the code. We can use them to explain complex sections of code. The interpreter ignores comments. Declare a comment using an octothorpe (#).

Indentation:Since Python doesn’t use curly braces to delimit blocks of code, Indentation is mandatory in Python. You can indent code under a function, loop, or class. White space is used as an indentation to highlight the blocks of code in Python.

Identifier: Identifier is a name given to entities like class, functions, variables, etc. It helps to differentiate one entity from another.

Get Yashaswini Suryawanshi’s stories in your inbox

Join Medium for free to get updates from this writer.

Rules for defining Identifiers:

  1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _. Names like myClass,screen1 and print_this, are all valid examples.
  2. Keywords cannot be used as identifiers.
Press enter or click to view image in full size

3.We cannot use special symbols like !, @, #, $, % etc. in our identifier.

Press enter or click to view image in full size

4.An identifier cannot start with a digit. 1digit is invalid, but digit1 is a valid name.

5.Identifier can be of any length.

SUMMARY : In this chapter, we have seen the various Syntaxes used in Python with relative examples.

In Next chapter, we will be looking into various data types and data structures in python.

To Be Continued…

--

--