Python: Syntax and Data types

Syeda
3 min readJun 11, 2024

--

Python has become one of the most popular programming languages due to its simplicity, readability, and versatility. Whether you’re a beginner just starting out or an experienced developer looking to explore a new language, understanding Python’s syntax and data types is crucial. In this blog, we’ll delve into the basics of Python syntax and explore its fundamental data types.

Understanding Python Syntax:

Python Syntax contains a set of rules that a programmer has to follow while writing a code.

Single line Comment- Comments in Python are marked by the # symbol and are used to explain code or prevent execution.

# This is a single-line comment

Single line multiple Comment- Multiline comments can be created using triple quotes.

“”” This is a multiline comment

“””

Identifiers- identifiers are names used to identify a variable, function, class, module, or other objects. They play a crucial role in writing clean and readable code. Understanding the rules and conventions for naming identifiers is essential for writing effective Python programs. Let’s dive into the details.

Rules for Naming Identifiers

Allowed Characters:

  • Identifiers can consist of letters (both uppercase and lowercase), digits, and underscores (_).
  • They must start with a letter (A-Z or a-z) or an underscore (_), followed by letters, digits, or underscores.

Case Sensitivity:

  • Python identifiers are case-sensitive, which means Variable and variable are considered different identifiers.
  • Reserved Words:
  • Identifiers should not be named using Python’s reserved words (keywords) such as if, else, while, for, class, def, etc. These are predefined in the language and serve specific purposes.

Variables- Variables are fundamental building blocks in programming, acting as containers for storing data values.

Keywords- Python keywords are reserved words that have special meaning and are used to define the syntax and structure of the Python language. They cannot be used as identifiers (variable names, function names, etc.).

Exploring Python Data types:

Python comes with a rich set of built-in data types, which can be categorized into the following groups:

Numerical Data types: numerical data types contains integer datatype, Float datatype and complex datatype.

  • int: Integer numbers, e.g., 1, 42, -3
  • float: Floating-point numbers, e.g., 3.14, -0.001
  • complex: Complex numbers, e.g., 1 + 2j

String: It is a sequence of character which is enclosed in ‘ ’, “ ”, or ‘‘‘ ’’’.

Properties of String Datatypes:

  1. String can have any single or a sequence of character.
  2. Strings are immutable.
  3. Inside the string each and every character will have an index value which consists of positive and negative index value for each.

String Methods

  1. lower(): convert all the upper case letter to lower case letter and ignore all the elements which are not alphabets
  2. upper(): convert all the lower case letter to upper case letter and ignore all the elements which are not alphabets
  3. Capitalize(): convert the first alphabet into upper case
  4. title(): convert the character into upper case of each alphabet of each alphabet sequence

--

--