DEV Community

Harish raj
Harish raj

Posted on

day 2 python

Introduction
Today, I learned about Python identifiers, variables, reserved keywords, built-in functions, data types, and ASCII. These are the fundamental concepts of Python programming that help us write and understand programs effectively.

  1. Variables and Identifiers in Python A variable is a name used to refer to a value in a program. In Python, a variable is created when we assign a value to a name.

An identifier is the name used to identify a variable, function, class, or another programming object.

Syntax:

name = "Harish"
age = 23
Here:

name and age are identifiers.

"Harish" and 23 are values.

= is the assignment operator.

The assignment operator assigns the value on the right-hand side to the name on the left-hand side.

Python variables are dynamically typed, which means we do not need to declare their data types explicitly.

  1. Rules for Naming Identifiers Python identifiers must follow specific naming rules.

They can contain uppercase letters (A–Z) and lowercase letters (a–z).

They can contain digits (0–9), but cannot start with a digit.

They can contain underscores (_).

They cannot contain spaces or special characters such as @, #, and $.

They cannot be Python reserved keywords.

Python is case-sensitive, so name, Name, and NAME are different identifiers.

Examples:

name = "Harish" # Valid
Name = "Raj" # Valid
user_name = "Harish" # Valid
age2 = 23 # Valid

2name = "Harish" # Invalid

user-name = "Raj" # Invalid

class = "Python" # Invalid

  1. Types of Naming Conventions Python uses underscores in different naming conventions to communicate the intended use of an identifier.

name = "Harish"
name = "Harish"
__name = "Harish"
__name
_ = "Harish"
name – A normal public-style name.

_name – A convention indicating that the name is intended for internal use.

__name – Inside a class, a leading double underscore triggers name mangling, which helps avoid naming conflicts with subclasses. It is not a strict privacy mechanism.

name – A name surrounded by double underscores is commonly reserved for special Python methods and attributes, such as init.

These naming conventions help developers communicate how identifiers are intended to be used.

  1. Reserved Keywords in Python Reserved keywords are words that have special meanings in Python's syntax. They cannot be used as ordinary identifiers, such as variable names.

Examples include:

if, else, for, while, def, class, return, import, True, and False.

For example:

if = 10 # SyntaxError
The word if is reserved for conditional statements, so it cannot be used as a variable name.

How to Display Python Keywords
Python provides the built-in keyword module to identify reserved keywords.

import keyword

print(keyword.kwlist)
print(len(keyword.kwlist))
import keyword imports the keyword module.

keyword.kwlist returns a list of Python keywords.

len(keyword.kwlist) counts the keywords in that list.

print() displays the results.

In Python 3.13, there are 35 hard keywords. The count can vary by Python version, and soft keywords are handled separately.

  1. Built-in Functions in Python A built-in function is a function provided by Python that we can use without defining it ourselves or importing a module.

Examples include:

print() – Displays output.

len() – Returns the length of an object.

type() – Returns the type of an object.

input() – Reads user input.

int() – Converts a compatible value to an integer.

Example:

name = "Python"

print(name)
print(len(name))
print(type(name))
Output:

Python
6

Here, print(), len(), and type() are built-in functions.

  1. What Is an IDE? IDE stands for Integrated Development Environment. It is a software application that provides tools for writing, running, debugging, and managing code.

Examples of Python development environments include:

Visual Studio Code

PyCharm

IDLE

JupyterLab

An IDE or code editor helps developers write programs more efficiently.

  1. Basic Data Types in Python Python provides different data types to represent different kinds of values.

Data type Description Example
int Whole numbers age = 23
float Decimal numbers price = 99.5
str Text name = "Python"
bool Boolean values is_valid = True
Integer
An integer represents a whole number without a decimal point.

age = 23
print(type(age))
Float
A float represents a number with a fractional or decimal component.

price = 99.5
print(type(price))
String
A string represents text enclosed in single or double quotation marks.

language = "Python"
print(type(language))
Boolean
A Boolean represents one of two logical values: True or False.

is_student = True
print(type(is_student))
Boolean values are not the same as the integers 1 and 0, although Python allows certain numeric operations between them.

  1. What Is ASCII? ASCII stands for American Standard Code for Information Interchange. It is a character-encoding standard that assigns numerical codes to English letters, digits, punctuation marks, and certain control characters.

For example:

A = 65

a = 97

0 = 48

Python can display the Unicode code point of a character using the ord() function.

print(ord("A"))
print(ord("a"))
print(ord("0"))
Output:

65
97
48
ASCII is a subset of Unicode. Python strings support Unicode, so Python can represent characters from many languages beyond the original ASCII character set.

Conclusion
Today, I learned the basics of Python identifiers, variable assignment, naming conventions, reserved keywords, built-in functions, IDEs, data types, and ASCII. These concepts form the foundation for writing Python programs and understanding how data is represented and processed.

By practising these fundamentals, I can build a stronger foundation for advanced Python topics such as functions, loops, object-oriented programming, data analysis, and artificial intelligence.

Top comments (0)