JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

python list V1.1 | JustPaste.app
22 days ago10 views
👨‍💻Programming

python list V1.1

when you want to create a variable, just type it's name and what it is:

name = "test" -> string

name = 1 -> int

name = 1.0 -> float

name = True -> boolean (important: the first letter needs to be capitalized (True/False))

names = ["Bob", "Gleb", "Len", "Nikita", "Mattis"] string list
numbers = [1, 4, 7] int list
numbers = [2.5, 4.0, 94.3] float list
booleans = [True, True, False] boolean list

to access a specific part of the list, just write:
list[x]
example:
list = ["hi", "what's up"]
print(list[1])

this will print

hi

you can also use inports to inport more functions.
example:

import random

to inport a few new functions, such as:

random(min, max) <- float
and
randint(min, max) <- int

you can also use it for lists:
foods = ["pancakes", "bread", "strawberries", "potato"]

print(random.choice(foods))
could print:
pancakes
or
bread
or
strawberries
or
potato

use sample instead of choice for multiple answers:

print(random.choice(foods, 2))
prints it like this:
['pancakes', 'potato']

use shuffle to randomly rearrange a list:
random.shuffle(foods)
from
foods = ["pancakes", "bread", "strawberries", "potato"]
to
foods = ["bread", "potato", "strawberries", "pancakes"]

you can also applay "weights" to the lists by using choices instead of choice, so they have different probabilities:
random.choices(
["common"], ["rare"],
[80], [20]
)

back to stuff that isn't from random:

use round(varibale) to round it up/down

if you want to make an if statement, write it like this:

if THING:
[TAB]thing that should happen

examples:

if test > 2 and test < 8:
  print("hooray")
else:
  print("aw man")

if test > 5 or test < -5:
  print("bob challenge 4")

if your code ends with
** Process exited - Return Code: 0 **
it means that nothing went wrong.

for loops:

if you want to make a for loop, write it like this:

for VARIABLE in range(0, LOOP_AMOUNT):
  print(VARIABLE)

if you type in this for example:

for i in range(0, 6):
  print(i)

it will print:

0
1
2
3
4
5

NOTE: it will stop before the the second number you inputted!

for loops are very useful when you're using lists.
example:
list = ["hi", "heloo", "what's up"]
for i in range(0, len(list)):
    print(list[i])

this will print:
hi
heloo
what's up

you can also let the user type in something
instead of using PRINT, use INPUT:

name = input("what's your name? ")

this will ask the user for their name and let them type it in. a simple program you could make using that would be:

name = input("hey! what is your name? ")

print("so your name is " + name + "?")

now, if you want the user to write a number, here is how you can check if it really is a number:

answer = 0
answer_input = input("hi, name me a random number: ")
  if anwer_input.isdigit():
    answer = int(answer_input)
  else:
    print("that isn't a number mate")

if you want to reuse code quickly, use a function:

import time

def colour(r=0, g=0, b=0):

    return f'\033[38;2;{r};{g};{b}m'

while True:

    party = input("wanna party? ")

    if party == "yes":

        while True:

            print(colour(255, 0, 0) + "party!")

            time.sleep(0.02)

            print(colour(255, 255, 0) + "party!")

            time.sleep(0.02)

            print(colour(0, 255, 0) + "party!")

            time.sleep(0.02)

            print(colour(0, 255, 255) + "party!")

            time.sleep(0.02)

            print(colour(0, 0, 255) + "party!")

            time.sleep(0.02)

            print(colour(255, 0, 255) + "party!")

            time.sleep(0.02)

    elif party == "no":

        print("aw man ):")

        exit()

    else:

        print("what..?")

here are more plugins that could help you:

import math

the math plugin provides useful math variables, such as:
math.pi: pi (3.141592653589793)
math.e: eulers number (2.718281828459045)
math.tau: 2 pi (6.283185307179586)
math.inf: infinite number (printing it will result it outputting "inf")
math.nan: nan means not a number.

math.ceil(x) always rounds up
math.floor(x) always rounds down
math.trunc(x) doesn't round, just removes decimal places

math.sqrt(x) square root
math.pow(x, y) x to the power of y
math.cbrt(x) cube root
math.isqrt(x) integer square root

etc (look it up yourself, there are way too many things it can do to describe in this guide)

← Back to timeline