


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Course Code PYCS
● Python is an interpreted, object-oriented, high-level programming language. ● Its creator is Guido van Rossum, and it was released in 1991. 1.1 WHY USE PYTHON? ● Easy to learn and use ○ Easy-to-read syntax ○ Intuitive ○ Easy to understand for beginners ● Versatile ○ Can be used for web development, data analysis, artificial intelligence, scientific computing, game development, and more. ● Large community and ecosystem: ○ Python has a large and active community of developers who contribute to the development of libraries and tools. ● Cross-platform support: ○ Can run on multiple operating systems: Windows, macOS, Linux ● High-level Language: ○ Designed to be human-readable, making it easier to write and maintain code. ● Interpreted language ○ In Python, there is no need to compile code before it can be executed. ○ So it means that it is faster and easier to write and test our code. 1.2 DATA TYPES Data Type Description Example str String, text Uses either single or double quotes. “Hello World” ‘I am 100 years old’ int Integers, whole numbers
float Floating point numbers, decimal numbers
bool Boolean, true or false True list Ordered, changeable collection of values. Uses square brackets []
tuple Ordered, (1,2,3)
unchangeable collection. Uses parentheses () set Unordered collection of unique values. Uses curly braces {}
dict Dictionary, stores key-value pairs {“name”: “Juan”} None Represents no value None 1.3 STRING ● String - series of characters interpreted as text. ● You can use either single or double quotes to define a string. name = 'John' name = "John" String Concatenation first = "John" last = "Doe" full_name = first + " " + last print(full_name) Output: John Doe f-strings One of the easiest ways to insert variables into strings: name = "John" age = 20 print(f"My name is {name} and I am {age} years old.") Output: My name is John and I am 20 years old. Multiple Line of Text Use 3 double quotes or 3 single quotes text = “””This is an example of multiple text in Python.””” print(text) Output: This is an example of multiple text in Python. String Formatting Functions upper() Converts into upper case lower() Converts into lower case capitalize() Converts the first character to uppercase title() Converts the first character of each word to uppercase split() Splits the string at the specified separator, and returns a list replace() Returns a string where a specified value is replaced with a specified value len() Count characters in a string 1.4 ARITHMETIC OPERATORS Operator Description
Converting one data type into another is called type casting. Common Conversions: ● int() ● float() ● str() ● bool() Example: number = "25" print(int(number) + 5) Output: 30