Category: Python


  • i=int(input(“enter total numbers”)) c=[] for j in range(i): c.append(int(input(“Enter a number”))) print(c) d=max(c) print(d)

  •   python CopyEdit num = int(input(“Enter a number: “)) if num % 2 == 0: print(“Even”) else: print(“Odd”)

  • Format Specifiers in Python Python provides format specifiers for formatting strings, numbers, and other data types. These specifiers can be used with f-strings (f””), the format() method, or % formatting. 1. Integer Formatting Format Description Example %d or {} Integer (decimal) print(f”{100:d}”) → 100 %o or {:#o} Octal representation print(f”{100:o}”) → 144 %x or {:#x}…

  • # Integer int_var = 42 print(“Integer:”, int_var, type(int_var)) # Float float_var = 3.14 print(“Float:”, float_var, type(float_var)) # Complex complex_var = 2 + 3j print(“Complex:”, complex_var, type(complex_var)) # Boolean bool_var = True print(“Boolean:”, bool_var, type(bool_var)) # String str_var = “Hello, Python!” print(“String:”, str_var, type(str_var)) # List (ordered, mutable collection) list_var = [1, 2, 3, “Python”, 4.5]…

  • Python has several built-in data types that help in storing and manipulating different kinds of data. Below is a detailed discussion of the various data types in Python: 1. Numeric Types Numeric data types store numbers and support arithmetic operations. a. int (Integer) Represents whole numbers (positive, negative, or zero). No limit on size (depends…

  • The .upper() method in Python is used to convert a string to uppercase. Syntax: string.upper() Example Usage: text = “hello world” upper_text = text.upper() print(upper_text) # Output: HELLO WORLD Calling upper() on a variable: name = “Python” print(name.upper()) # Output: PYTHON Calling upper() directly on a string literal: print(“hello”.upper()) # Output: HELLO Would you like…