0% found this document useful (0 votes)
0 views34 pages

Fundamentalspython

The document explains complex numbers in Python, including their creation, accessing real and imaginary parts, and performing arithmetic operations. It also covers Boolean data types, sequences (strings, lists, and tuples), mappings (dictionaries), and the special constant None. Additionally, it provides examples and code snippets for better understanding of these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views34 pages

Fundamentalspython

The document explains complex numbers in Python, including their creation, accessing real and imaginary parts, and performing arithmetic operations. It also covers Boolean data types, sequences (strings, lists, and tuples), mappings (dictionaries), and the special constant None. Additionally, it provides examples and code snippets for better understanding of these concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

What is a Complex Number?

A complex number has two parts:


1)Real part
2)Imaginary part
📌 In Python, complex numbers are written
as
x = 2 + 3j
✅ Python uses j to represent the imaginary
unit (√-1)
• How to Create Complex Numbers
x = 5 + 4j
y = 3 - 2j
3. Accessing Real and Imaginary Parts
Use .real and .imag to get the parts:
print(x.real)
print(x.imag)
✅ Python returns these as floating-point numbers.
4. Arithmetic Operations
x = 2 + 5j
y = 4 - 2j
z=x+y
• x=3.15+5.6j
• y=4.13+6.2j
• z=y-x
• print(z)
• print((round(z.real,2)+round(z.imag,2)))
• 1. Create a complex number a = 3 + 2j and print its real and imaginary
parts.
2. Write a program to add two complex numbers.
3. a = 3 + 2j
b = 1 + 7j
• print("Addition:", a + b)
print("Subtraction:", a - b)
What is a Boolean?
•A Boolean is a data type that can store only two possible values:
•True
•False

•Boolean values are used for decision-making in programs in python .


•True and False are keywords
a=5
b=3

•print(a > b)
•print(a == b)
•print(a != b)
• Boolean in Arithmetic:
print(True + True)
• print(False + True)
• print(True * 5)
• What is a Sequence?
• A sequence in Python is an ordered collection of items.
Each item in a sequence is assigned a position (index).
Types of sequences in Python :

Sequence Type Description


string A sequence of characters
list A sequence of items (can be different types)
tuple A sequence of items (immutable)
• String: is an ordered sequence of letters/characters.
They are enclosed in single quotes („ ‟) or double („‟ “).
The quotes are not part of string.
They only tell the computer where the string constant begins and
ends.
They can have any character or sign, including space in them.
These are immutable data types.
• If we are not sure, what is the data type of a value,
Python interpreter can tell us:
>>>type (“Good Morning‟)
<type “str‟>
>>> type (“3.2‟)
<type”str‟>
"Strings in Python are immutable, meaning once a string
is created, its contents cannot be changed."
•Single-line: "text" or 'text'
•Multi-line: Triple quotes """text""" or with
backslashes
•Escape characters: \n, \t, \\, etc.
•Use len() to find the string length
• Lists: List is also a sequence of values of any type.
Values in the list are called elements / items.
These are mutable and indexed/ordered.
List is enclosed in square brackets.
Example l = [“spam”, 20.5,5]
• Tuples: Tuples are a sequence of values of any type, and are indexed
by integers. They are immutable. Tuples are enclosed in ().
• T=(7,8)
List and Tuple as Sequences

List Example:
numbers = [10, 20, 30] print(numbers[1]) #
Output: 20
Lists are mutable: their elements can be changed.
Tuple Example:
colors = ('red', 'green', 'blue') print(colors[0]) #
Output: red
Tuples are immutable.
What is Mapping?
A mapping is a collection of key-value pairs.
In Python, the most commonly used mapping type is the dictionary.
A dictionary stores data in the form of key: value pairs.
Each key is unique, and it is used to access its corresponding value.
student = {
"name": "Ravi",
"age": 17,
"class": "11A"
}
• Dictionaries: Can store any number of python objects.
What they store is a key – value pairs,
which are accessed using key.
Dictionary is enclosed in curly brackets.
Example d = {1:'a',2:'b',3:'c'}
What is None?
None is a special constant in Python that represents the absence of a value or a null value.
It is often used to indicate that a variable exists but does not have any meaningful value yet.
•None is a data type of its own — the NoneType.
•It is not equal to 0, False, or an empty string
• Value of Object (variable) – to bind value to a variable, we use
assignment operator (=).
This is also known as building of a variable.
Example >>> pi = 31415 Here, value on RHS of
• “=‟ is assigned to newly created
• “pi‟ variable.
num_years = 4
days_per_year = 365
hours_per_day = 24 mins_per_hour = 60 secs_per_min = 60

total_secs = secs_per_min * mins_per_hour * hours_per_day * days_per_year *


num_years
Print (total_secs)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy