Basic Syntax of Python

 The Python syntax defines a set of rules that are used to create Python statements while writing a Python Program. The Python Programming Language Syntax has many similarities to Perl, C, and Java Programming Languages. However, there are some definite differences between the languages.


First Python Program

Let us execute a Python "Hello, World!" Programs in different modes of programming.

$ python
Python 3.6.8 (default, Sep 10 2021, 09:13:53)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Here >>> denotes a Python Command Prompt where you can type your commands. Let's type the following text at the Python prompt and press the Enter −


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

We assume that you have Python interpreter path set in PATH variable. Now, let's try to run this program as follows −

$ python first.py

Python Identifiers

A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).

Here are naming conventions for Python identifiers −

  • Python Class names start with an uppercase letter. All other identifiers start with a lowercase letter.

  • Starting an identifier with a single leading underscore indicates that the identifier is private identifier.

  • Starting an identifier with two leading underscores indicates a strongly private identifier.

  • If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.































No comments:

Post a Comment