🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Copy of Chapter 1 - Statements (1).pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Libraries 01 Standard Library Comes with Python, offering tools for common tasks like data extraction and report generation. External Library 02 Developed by the community for vario...

Libraries 01 Standard Library Comes with Python, offering tools for common tasks like data extraction and report generation. External Library 02 Developed by the community for various purposes, such as Pandas for data analysis. Python 1. Conciseness 2. structure Syntax Python Java public class Hello { public static void main(String[] args) { print("Hello, World!") System.out.println("Hello, World!"); } } Try: print("What is your favorite song?") song = input() print("Cool! I like", song, "too.") Input/ Output Basic print() displays output. Use sep and end to Output customize output. Code Output print("Today is Monday.") Today is Monday. print("I like string beans.") I like string beans. print("Today", "is", "Monday") Today is Monday print("Today", "is", "Monday", sep="...") Today...is...Monday print("Today is Monday, ", end="") Today is Monday, I like stringbeans. print("I like string beans.") print("Today", "is", "Monday", sep="? ",end="!!") Today? is? Monday!!I like print("I like string beans.") stringbeans. Basic variable = input("prompt") Input Try: # Ask the user for their name name = input("What is your name? ") # Ask the user what they like likes = input("What do you like? ") # Show the user's name and what they like print("Your name is " + name + ".") print("You like " + likes + ".") Variables 01 Assignment Statement Sets a variable to a value using the assignment operator (`=`) Variables 02 Variable Name Rules Can include letters, digits, and underscores; cannot start with a digit. Letter case matters. 03 Name Descriptions Should be short and descriptive. Use words instead of single characters for Variables better readability 04 Reserved Words Python has reserved keywords with special functions that cannot be used as variable names. String Basics A string is a sequence of String characters enclosed by Basics matching single (`'`) or double (`"`) quotes The len() len() function, when called on a string function value, returns the string length. number = "12" number_of_digits = len(number) print("Number", number, "has", number_of_digits, "digits.") Concatenation combines two or more strings sequentially concatenation using the + operator. Example: "A" + "part" produces the string "Apart". Number Basics Numeric Integer Floating-point Data Types Used for String representing text x=1 y = 2.0 s = "32" print(x, type(x)) 1 print(y, type(y)) 2.0 print(s, type(s)) 32 Used to perform Basic mathematical operations like addition, subtraction, Arithmetic multiplication, and division. Operator Operators are evaluated in order of precedence. Precedence Operator Description Example Result () Parentheses (1 + 2) * 3 9 ** Exponentiation 2 ** 4 16 +,- Positive, negative -math.pi -3.14159 Multiplication, *,/ 2*3 6 division Addition, +,- 1+2 3 subtraction Single-line Comments: Begin with the # symbol. Comments Multi-line Comments: Use triple quotes (''' or """)

Use Quizgecko on...
Browser
Browser