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

1.1 Introduction , Variables,Data Types

Python is a high-level, interpreted programming language known for its readability and support for multiple programming paradigms. It features a simple syntax, dynamic typing, extensive libraries, and strong community support. The document also covers variables, naming conventions, and various built-in data types, including numeric, string, boolean, sequence, mapping, and set types, along with type conversion methods.

Uploaded by

Akshat Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

1.1 Introduction , Variables,Data Types

Python is a high-level, interpreted programming language known for its readability and support for multiple programming paradigms. It features a simple syntax, dynamic typing, extensive libraries, and strong community support. The document also covers variables, naming conventions, and various built-in data types, including numeric, string, boolean, sequence, mapping, and set types, along with type conversion methods.

Uploaded by

Akshat Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Python

What is Python?

 is a high-level, interpreted programming language known for its


ease of use and readability. It supports multiple programming
paradigms, including procedural, object-oriented, and functional
programming.

Features of Python:

 Simple and Readable: syntax is clean and easy to understand.

 Interpreted: code is executed line-by-line at runtime, which makes


debugging easier.

 Dynamically Typed: No need to declare the data type of a


variable; it’s inferred at runtime.

 Extensive Libraries: has a vast standard library and many third-


party libraries.

 Community Support: boasts a large, active community that


contributes to its rich ecosystem.

Getting Started:

 Installation: Download from python.org and install it.

 Running Code: You can run code in an interactive shell, script files,
or integrated development environments (IDEs) like PyCharm, VS
Code, etc.

Variables in Python

What is a Variable?

 A variable is a named location used to store data in memory. It is


given a name to allow the data to be easily referenced and
manipulated in a program.

Naming Conventions:

 Variable names must start with a letter or an underscore (_).

 They can be followed by letters, digits, or underscores.

 Variable names are case-sensitive (e.g., age and Age are different).

 Avoid using Python’s reserved keywords as variable names (e.g., if,


for, while).

Example:
python

name = "Alice"

age = 25

is_student = True

Data Types in Python

What is a Data Type?

 A data type specifies the type of data that a variable can hold. has
various built-in data types that cater to different kinds of values.

Common Data Types:

1. Numeric Types:

o int: Represents integers, e.g.,age = 25

o float: Represents floating-point numbers, e.g.,pi = 3.14

o complex: Represents complex numbers,


e.g.,complex_number = 2 + 3j

2. String Type:

o str: Represents a sequence of characters, e.g.,name = "John"

3. Boolean Type:

o bool: Represents Boolean values (True or False), e.g.,is_sunny


= True

4. Sequence Types:

o list: Represents an ordered collection of items, e.g.,fruits =


["apple", "banana", "cherry"]

o tuple: Represents an ordered, immutable collection of items,


e.g.,coordinates = (10, 20)

o range: Represents a sequence of numbers, e.g.,numbers =


range(1, 10)

5. Mapping Type:

o dict: Represents a collection of key-value pairs, e.g.,person =


{"name": "John", "age": 25}

6. Set Types:
o set: Represents an unordered collection of unique items,
e.g.,unique_numbers = {1, 2, 3, 4, 5}

frozenset: Represents an immutable set, e.g.,frozen_set =


frozenset([1, 2, 3])

Type Conversion:

 Implicit Conversion: automatically converts one data type to


another when necessary.

x = 10

y = 5.5

result = x + y # x is implicitly converted to float

 Explicit Conversion: You can manually convert data types using


constructor functions like int(), float(), str(), etc.

x = "10"

converted_x = int(x)

You might also like