0% found this document useful (0 votes)
4 views5 pages

Notes

This document provides an overview of Python basics, including syntax rules, input/output functions, numeric types, arithmetic operators, string methods, and lists. It includes examples of code snippets demonstrating each concept and outlines important rules for variable naming and data types. The content is structured to aid beginners in understanding fundamental programming concepts in Python.

Uploaded by

ryanryanyeoh
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)
4 views5 pages

Notes

This document provides an overview of Python basics, including syntax rules, input/output functions, numeric types, arithmetic operators, string methods, and lists. It includes examples of code snippets demonstrating each concept and outlines important rules for variable naming and data types. The content is structured to aid beginners in understanding fundamental programming concepts in Python.

Uploaded by

ryanryanyeoh
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

SECTION C

1. Example:

python

print("Hello World")

print("Programming is fun")

2. Example:

python

banana_count = 10 # Stores number of bananas

3. favourite_colour = "Blue"

4. Example:

python

print("My favorite colour is " + favourite_colour)

5. Example:

python

print("She said, \"Hello!\"")

6. Rules:

o Cannot start with a digit

o No special characters except underscore

o Case-sensitive

7. Example:

python

"python programming".upper()

8. Example:

python

text = input()

print([Link]())

9. Example:
python

base = 5

height = 8

area = (base * height) / 2

10. += adds to variable; /= divides variable by value and reassigns.

Python Basics Learning Notes

1. Introduction to Python

 Why Python?

o Easy to learn with readable syntax.

o Widely used in web development, AI, data science, and


automation.

o Great for beginners.

 Basic Syntax Rules:

o Uses indentation (spaces/tabs) for code blocks.

o Case-sensitive (Name ≠ name).

o Each command typically goes on a new line.

2. Input and Output

 print() Function:

o Displays output on the screen.

o Syntax: print("message")

 input() Function:

o Takes user input.

o Syntax: variable = input("prompt")

o Returns a string by default.

 Example:

python
name = input("What is your name? ")

print("Hello,", name)

3. Python Numbers

 Three Numeric Types:

1. int – Whole numbers (e.g., 5)

2. float – Decimal numbers (e.g., 3.14)

3. complex – Imaginary numbers (e.g., 3+4j)

 Type Checking:

o Use type() to check the data type: type(variable)

 Type Conversion:

o Convert between types using:

 int(), float(), complex()

o Example:

python

x=1 # int

y = float(x) # becomes 1.0

4. Arithmetic Operators

 Basic Operators:

o + Addition

o - Subtraction

o * Multiplication

o / Division

o % Modulus (remainder)

o ** Exponentiation (power)

o // Floor division (integer division)


 Assignment Operators:

o =, +=, -=, *=, /=, %=, **=, //=

 Example:

python

a=5

a += 3 # a is now 8

5. Strings and String Methods

 String Methods:

o lower() / upper() – Change case

o title() – Capitalizes each word

o capitalize() – Capitalizes first character

o replace(old, new) – Replaces text

o count(substring) – Counts occurrences

o find(substring) – Returns position

o expandtabs(tabsize) – Adjusts tabs

 Example:

python

text = "Hello World"

print([Link]()) # HELLO WORLD

6. Lists

 Definition:

o A collection of items stored in a single variable.

o Created with square brackets: list = ["item1", "item2"]

 List Features:

o Can contain mixed data types.


o Allows duplicate values.

o Indexed (starts at 0).

 Common List Methods:

o append(item) – Adds item to end

o remove(item) – Removes item

o sort() – Sorts list

o len(list) – Returns length

 Example:

python

fruits = ["apple", "banana", "cherry"]

print(fruits[1]) # banana

[Link]("orange")

You might also like