0% found this document useful (0 votes)
9 views4 pages

CSE 301 Lecture1 Python

This lecture introduces basic Python concepts including printing, comments, variables, data types, numbers, casting, and string manipulation. It covers how to display information, annotate code, store data, and perform operations on different data types. Additionally, it explains string basics such as slicing, modifying, and concatenating strings.

Uploaded by

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

CSE 301 Lecture1 Python

This lecture introduces basic Python concepts including printing, comments, variables, data types, numbers, casting, and string manipulation. It covers how to display information, annotate code, store data, and perform operations on different data types. Additionally, it explains string basics such as slicing, modifying, and concatenating strings.

Uploaded by

forcseacademic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lecture 1: Python Begins...

How to use notebook, prining, comment, variables, data-types, numbers,


casting, strings

1. Printing
Printing is a fundamental operation in programming. It allows you to display information to the
console.

Here, print() is a function in Python that displays the text "Hello, World!" to the console.

print("Hello, World!",end =' ')


print('uap')

Hello, World! uap

2. Comments
Comments are used to annotate your code, providing information to make it more readable. In
Python, comments start with the # symbol.

# This is a single-line comment

"""
This is a
multi-line comment
"""

{"type":"string"}

3. Variables
Variables are containers for storing data. You can think of them as named storage locations.

Here, name is a variable storing a string, and age is a variable storing an integer.

name = "John"
age = 25

4. Data Types
Python has various data types, including integers, floats, strings, and booleans.

integer_number = 42
decimal_number = 3.14
text = '"Hello, World!"'
is_python_fun = True

print(type(text))
text

<class 'str'>

{"type":"string"}

5. Numbers
Numbers in Python can be integers or floating-point (decimal) numbers.

# Integers
x = 5

# Floats
y = 3.14

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

# Casting to integer
a = 5.6 # a will be 5
print(type(a), a)
a = int(a)
print(type(a), a)

# Casting to float
b = float(3) # b will be 3.0
print(type(b), b)

# Casting to string
c = str(42) # c will be "42"
print(type(c),c)

<class 'float'> 5.6


<class 'int'> 5
<class 'float'> 3.0
<class 'str'> 42

7. Strings basics
Strings are sequences of characters. You can manipulate and concatenate them.

a = 'hello world'
print(a)
hello world

a = """Lorem ipsum dolor sit amet,


consectetur adipiscing elit,

sed do eiusmod tempor incididunt


ut labore et dolore magna aliqua."""
print(a)
#length
print(len(a))

Lorem ipsum dolor sit amet,


consectetur adipiscing elit,

sed do eiusmod tempor incididunt


ut labore et dolore magna aliqua.
133

# Slicing
b = "hello"
print(b[-1:-4])

# Slicing
b = "Hello, World!_ap cse "
print(len(b[-10:-7]))
print((b[-10:-7]))

3
d!_

# modify String
a = "Hello, World!"
print(a.upper())

a = " Hello, World! "


print(a.strip()) # returns "Hello, World!"

HELLO, WORLD!
Hello, World!

#replace
a = "Hello, World!"
print(a.replace("H", "J"))

Jello, World!
# concate
a = "Hello"
b = "World"
c = a +" awseome " + b + str(52)
print(c)

Hello awseome World52

a = 50
c = 15
d = str(a) + str(c) + ' hello '
d

{"type":"string"}

m = 50

print(m)

50

a = 'hello world '


b = a[-7:-1]
b = b.replace('o','k')
print(b)
print(len(b))

wkrld
6

You might also like