0% found this document useful (0 votes)
3 views6 pages

Programming Language Fundamentals Explained

The document outlines the basics of programming languages, covering data types, expressions, variables, and keywords essential for coding. It explains operator precedence and the use of comments to enhance code readability. Additionally, it distinguishes between Interactive Mode and Script Mode in Python for executing code.

Uploaded by

Devi Pagavan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Programming Language Fundamentals Explained

The document outlines the basics of programming languages, covering data types, expressions, variables, and keywords essential for coding. It explains operator precedence and the use of comments to enhance code readability. Additionally, it distinguishes between Interactive Mode and Script Mode in Python for executing code.

Uploaded by

Devi Pagavan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Language Basics: Data,

Expressions, Variables, and Keywords


Understanding the fundamental building blocks of programming languages is essential for writing
efficient and structured code. The key components include data types, expressions, variables, and
keywords.

1. Data Types
Data types define the kind of values that can be stored and manipulated in a program.

Common Data Types in Programming


Data Type Description Example
Integer (int) Whole numbers 10, -5, 0
Floating-point (float, double) Decimal numbers 3.14, -0.99
Character (char) Single letter or symbol 'A', '$', '5'
String (str) Sequence of characters "Hello", "123"
Boolean (bool) True or False values True, False
List/Array Collection of values [1,2,3], ["a", "b"]
Dictionary (dict, hash map) Key-value pairs {"name": "John", "age": 25}
? Example in Python:
age = 25 # Integer
price = 99.99 # Float
name = "Alice" # String
is_active = True # Boolean
fruits = ["apple", "banana", "cherry"] # List

2. Expressions
An expression is a combination of values, variables, operators, and function calls that evaluate to a
result.

Examples of Expressions
Expression Description Example
Arithmetic Expression Mathematical operations 5 + 3, x * y - 2
Logical Expression Boolean logic a > b, x == y and z < 10
String Concatenation Joining strings "Hello " + "World"
Function Calls Evaluating functions max(10, 20), len(name)
? Example in Python:
x = 10
y = 20
sum_result = x + y # Arithmetic expression
is_greater = x > y # Logical expression
message = "Hello" + " World" # String expression

3. Variables
A variable is a named storage location for data. The value of a variable can change during program
execution.

Variable Naming Rules


✅ Must begin with a letter (A-Z, a-z) or underscore _
✅ Can contain letters, numbers (0-9), and underscores (_)
✅ Case-sensitive (age and Age are different)
❌ Cannot be a keyword (e.g., if, while, def)

? Example in Python:
name = "Alice" # Assigning a string to a variable
age = 25 # Assigning an integer
price = 9.99 # Assigning a float
is_logged_in = True # Boolean variable

4. Keywords
Keywords are reserved words in a programming language that have special meanings and cannot
be used as variable names.

Common Keywords in Python


Category Keywords
Control Flow if, else, elif, for, while, break, continue
Function & Class def, return, class, lambda
Boolean & None True, False, None
Exception Handling try, except, finally, raise
Data Handling import, global, nonlocal, del, pass
? Example in Python:
if age > 18:
print("You are an adult.")

Conclusion
 Data types define the nature of values in programming.
 Expressions combine variables, operators, and functions to produce a result.
 Variables store values for later use.
 Keywords are reserved words with special meanings.
Would you like examples in another language like C, Java, or JavaScript? ?
Operator Precedence and Comments in
Programming
Understanding operator precedence ensures correct evaluation of expressions, and using
comments makes code readable and maintainable.

1. Operator Precedence
What is Operator Precedence?
Operator precedence determines the order in which operators are evaluated in an expression.
Operators with higher precedence are executed first.

Order of Precedence (from Highest to Lowest)


Precedence Operators Example
1 (Highest) (), [], {} (Parentheses, Brackets) (2 + 3) * 5
2 ** (Exponentiation) 2 ** 3 → 8
3 +x, -x, ~x (Unary operators) -5, +3
4 *, /, //, % (Multiplication, Division) 10 / 2 → 5.0
5 +, - (Addition, Subtraction) 5 + 3 → 8
6 <<, >> (Bitwise shift) 4 << 1 → 8
7 & (Bitwise AND) 5 & 3 → 1
8 ^ (Bitwise XOR) 5 ^ 3 → 6
9 ` ` (Bitwise OR)
10 ==, !=, >, <, >=, <= (Comparison) 5 > 3 → True
11 not (Logical NOT) not False → True
12 and (Logical AND) True and False → False
13 or (Logical OR) True or False → True
14 (Lowest) =, +=, -=, *=, /=, %=, **=, //= (Assignment) x = 10
? Example in Python:
result = 10 + 3 * 2 # 3 * 2 is evaluated first, then added to 10 → result = 16
result = (10 + 3) * 2 # Parentheses force addition first → result = 26

2. Comments in Programming
What are Comments?
Comments are non-executable lines used to describe code, making it more understandable.

Types of Comments
a) Single-Line Comments (# in Python, // in C/Java/JS)
Used for brief explanations.
? Example in Python:
# This is a single-line comment
x = 10 # Assigning 10 to x

? Example in JavaScript:
// This is a single-line comment
let x = 10; // Assigns 10 to x

b) Multi-Line Comments (''' or """ in Python, /* ... */ in C/Java/JS)


Used for larger descriptions.
? Example in Python:
"""
This is a multi-line comment.
It is used for detailed explanations.
"""
print("Hello, world!")

? Example in C/JavaScript:
/* This is a multi-line comment
explaining multiple lines of code */
printf("Hello, world!");

Conclusion
 Operator precedence defines the execution order of operators.
 Parentheses can be used to control precedence.
 Comments improve readability but do not affect code execution.
Would you like examples in another language (C, Java, JavaScript)? ?

Python: Interactive Mode vs. Script Mode ?


Python can be executed in two main ways:
1 Interactive Mode (REPL - Read, Evaluate, Print, Loop)
1️⃣
2️⃣Script Mode (Running .py files)

1. Interactive Mode (REPL) ?￯ᄌマ


What is Interactive Mode?
 Runs Python commands line by line.
 Used for quick testing and debugging.
 No need to save a file—just type and execute.

How to Use Interactive Mode?


a) Open Python in the Terminal/Command Prompt
python
OR
python3

? Example:
>>> print("Hello, World!")
Hello, World!
>>> 5 + 3
8
>>> x = 10
>>> x * 2
20

? Key Features:
✅ Instant execution of commands
✅ Good for testing small code snippets
✅ No need to save a file

Exit Interactive Mode


Use one of these commands:
exit()
quit()
Ctrl + D (Linux/macOS)
Ctrl + Z + Enter (Windows)

2. Script Mode (Running Python Files) ?


What is Script Mode?
 Used for writing full programs in a .py file.
 The script runs as a whole, instead of line by line.
 Allows saving and reusing code.

How to Write and Run a Python Script?


a) Create a Python File
Write Python code in a file, e.g., [Link]:
# [Link]
print("Hello, World!")
x = 10
y = 20
print("Sum:", x + y)

b) Run the Script in the Terminal/Command Prompt


python [Link]

OR
python3 [Link]
? Key Features:
✅ Best for writing complete programs
✅ Code can be saved and reused
✅ Supports functions, loops, and complex logic

Comparison: Interactive vs. Script Mode


Feature Interactive Mode Script Mode
Execution Line by line Entire file at once
Use Case Quick testing/debugging Full programs
File Needed? ❌ No ✅ Yes (.py file)
Best For Learning, small code snippets Large projects, reusable code

Conclusion
 Use Interactive Mode for quick tests and learning.
 Use Script Mode for writing complete applications.
Would you like a guide on writing your first Python program? ?

You might also like