Python Basic

PRAVESH GREWAL
Python’s Gurus
Published in
3 min readJun 17, 2024

let’s understand some basic concepts of python

Syntex:-

Syntax refers to the set of rules defining the combination of symbols considered correctly structured programs in a language. In simple terms, syntax is the correct arrangement of words and symbols in a code.

Semantics:-

Semantics pertains to the meaning or interpretation of a language's symbols, characters, and commands. It involves what the code is intended to accomplish when executed.

Basic syntax rules in python:-

Case Sensitive:-

Python is a case-sensitive programming language:-

#case sensitive 
Name = "Pravesh"
name = "Grewal"
print(Name)
print(name)

Here we can see the "name" and "Name" variables are considered as different variables. Based on this example, we can say Python is a case-sensitive language.

Comments in Python:-

we have two types of comments in Python: single-line comments and multi-line comments.

Indentation:-

Python uses indentation to define blocks of code. Consistent use of spaces or tabs is required.
In Python, indentation is used to define the structure and hierarchy of the code. Unlike many other programming languages that use braces {} to delimit blocks of code, Python uses indentation to determine the grouping of statements. This means that all the statements within a block must be indented at the same level.

#indentation
age = 69
if age > 30:
print(age)

print(age)

Line Continuation: —

Remember to use a backslash (\) to continue a statement to the next line.

# line continuation
sum = 3+9+9+7+86\
+8+96

print(sum)

Multiple statements in a single line:-

output

Variable assignment:-

In other programming languages, we need to define the data types of variables. However, in Python, we don't need to define any data type.

Here we can see that age is an integer and naam is a string. We don't need to define data types here.

Some types of errors in Python:-

# SyntaxError: invalid syntax
if True
print("This will cause a syntax error")
# IndentationError: expected an indented block
def my_function():
print("Incorrect indentation")
# TypeError: unsupported operand type(s) for +: 'int' and 'str'
result = 5 + "10"
# NameError: name 'x' is not defined
print(x)

Python’s Gurus🚀

Thank you for being a part of the Python’s Gurus community!

Before you go:

  • Be sure to clap x50 time and follow the writer ️👏️️
  • Follow us: Newsletter
  • Do you aspire to become a Guru too? Submit your best article or draft to reach our audience.

--

--

PRAVESH GREWAL
Python’s Gurus

Artificial intelligence, Computer-Networking ,Python & Cyber-Security