• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
Python | Variables
  1. Variables
  2. Comment
  3. Numbers
  4. Strings
  5. Dates

  1. Variables
    Variables names:
    • Variables names can contain only letters, numbers, and/or underscores.
    • Variables names can't start with a number.

    Define a variable:
    Multiple assignment:
  2. Comments
    To comment a line or part of a line, use the hash mark character (#).
  3. Numbers
    Integers: 1, 2, ...
    Floats, 1.0, 2.0, ...
    Operations: +, -, *, /, \%, ** (exponents)

    Using underscores between digits in numeric literals:
    Modulo operator:
  4. Strings

    Changing string case:
    Formating a string (f-strings):
    To use a variable or a function inside a string, place the letter f before opening quotation mark.
    Inside the string put any variable or function you want to use and surround it with braces.
    Adding whitespace to strings with tabs (\t) or newlines (\n):
    Stripping whitespace:
    Removing prefixes and suffixes:
    Split words:
    Split lines:
    Convert string to int:
  5. Dates
    Parsing a string date using a specific format:
    Date and time formating:
    • %d: Day of the month (01 - 31)
    • %m: Month (01 - 12)
    • %y: Two-digit year (23, ...)
    • %Y: Four-digit year (2023, ...)
    • %I: Hour, in 12-hour format (00 - 12)
    • %H: Hour, in 24-hour format (00 - 23)
    • %p: AM|PM
    • %M: Minutes (00 - 59)
    • %S: Seconds (00 - 59)
    • %A: Weekday name (Monday, ...)
    • %B: Month name (January, ...)
© 2025  mtitek