0% found this document useful (0 votes)
2 views

Programming Basics

The document provides a comprehensive overview of programming basics, focusing on data types, including primitive, composite, and abstract data types. It also covers casting, operators, constants, and variables, as well as string operations. Understanding these concepts is essential for effective data manipulation in programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming Basics

The document provides a comprehensive overview of programming basics, focusing on data types, including primitive, composite, and abstract data types. It also covers casting, operators, constants, and variables, as well as string operations. Understanding these concepts is essential for effective data manipulation in programming.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Basics - Comprehensive Explanation

1. Data Types

Data types define the nature of data that can be stored and manipulated in a programming

language.

They determine the kind of operations that can be performed on a given piece of data.

Types of Data:

1. Primitive Data Types - Basic types of data that represent single values.

2. Composite Data Types - Collections or groupings of values.

3. Abstract Data Types (ADTs) - Data structures designed for specific functionalities.

Primitive Data Types

- Integer (int): Whole numbers (e.g., 10, -5, 200)

- Floating-Point (float): Numbers with decimal points (e.g., 3.14, -0.001, 2.0)

- Boolean (bool): Represents True or False values

- String (str): Sequence of characters (e.g., "Hello, World!", 'Python')

Composite Data Types

- List (list): Ordered, mutable collection of elements. Example: [1, 2, 3, "apple"]

- Tuple (tuple): Ordered, immutable collection. Example: (5, "banana", 3.14)

- Dictionary (dict): Key-value pairs, unordered, mutable. Example: {"name": "John", "age": 25}

- Set (set): Unordered collection of unique elements. Example: {1, 2, 3, 4}

2. Casting and Operators

Casting
Casting is the process of converting one data type into another.

Examples:

- Integer to String: str(100) -> "100"

- String to Integer: int("50") -> 50

- Float to Integer: int(3.14) -> 3

Operators

Operators are symbols that perform operations on variables and values.

- Arithmetic Operators: +, -, *, /, //, %, **

- Comparison Operators: ==, !=, >, <, >=, <=

- Logical Operators: and, or, not

- Assignment Operators: =, +=, -=, *=

3. Constants and Variables

Variables store data values that can change during program execution.

Example:

name = "John" # String variable

age = 25 # Integer variable

Constants do not change:

PI = 3.14159

4. Strings

A string (str) is a sequence of characters enclosed in quotes.


Operations:

- Concatenation: "Hello" + " " + "World" -> "Hello World"

- Indexing: text[0] -> 'H'

- Slicing: text[:5] -> 'Hello'

- Methods: text.upper(), text.lower(), text.replace("hello", "hi")

Conclusion

Understanding these programming basics is crucial for working with data effectively.

You might also like