Learn to Code via Tutorials on Repl.it!

← Back to all posts
Professional Python Antics
Jakman (451)

Ok since you guys seem to like python so much and every other language's tutorials die in new here is something for you braindead script kiddies.

Chapter 1 List Comprehension Crap

Sometimes you will want to do operations on a list to return a new list. This is where list comprehensions come into play.
They do just that. For instance if i wanted every even number multiplied by five from 1 to 10 i would call this code

list(filter(lambda a: a%2 == 0,[x*5 for x in range(1,10+1)]))

The list comprehension is the list on the right.
It takes every thing inside of the range of 1 to 11 (x) and returns that multiplied by 5.

Chapter 2 Sys module

I saw that little post about beginners python modules. Its alright but it can be improved upon. The sys module is for command line arugument foolery and functionality with when to end programs. We will be focusing on command line args.
They are just the things you type to run a program in the terminal.
A list inside sys is called argv. This is the list of command line arguments that you put in to run the program.
The first argument (sys.argv[0]) is just the file name but everything after that are the arguments. (sys.argv[1]) and beyond. You can give functionality to these args via if statements such as

if sys.argv[1] == read:
    print("you are not reading. The library does not approve")

This gives the "read" argument functionality in your program. The best part is is that you can give it whatever ability you want.

If you have any questions so far just ping me.

Chapter 3 making your own modules.

Some of you guys only know how to make games in python. That's ok but let me let you in on some knowledge (THAT IS NOT GOING TO GET YOU ANYWHERE) You might want to have your own modules and libraries in python so that you can organize functionality and seperate code betwixt files. This is easy to do as we are not working with Rust.
Just define the functions in one file and import that file with the name of that file. For instance.

def shoot(num):
    for i in range(0,int(num)+1):


import lib # lib is the name of the file so we must import from lib

Chapter 4 The Shutil module

shutil allows you to do advanced IO tricks that the os module does not allow you to do.
For example you can remove a folder with contents inside it. You can also copy files in one line. And much more.

This concludes my Ted Talk. I am not selling T shirts.

Words of Wisdom

Every statically typed programming language should have a type for functions.

DynamicSquid (3558)

You know, I've been thinking about the "perfect" language. It'll be a combination of C, C++, and Java.

Unlike C or Java, it won't have a main class/function, so kinda like Python.

It will have classes like C++ (no multiple inheritance, and only public inheritance).

It will have pointers like C/C++, and auto garbage collection like Java.

It will have templates, namespaces.

And the standard library will feature predefined data types (string, list, etc.) in two versions, and procedural and OOP style

Good language?

Jakman (451)

@DynamicSquid oh that's good. You will want functional functionalities and a drawn from keyword like seen in haskell.

EpicGamer007 (540)

@DynamicSquid, I would also add that it should be able to support some high level stuff and low level stuff. And have a big(ish) standard library

CodeLongAndPros (1354)

@Jakman (if (eq? ‘functional ‘functionalities) ( function functionalities) ())

Jakman (451)

@AbhayBhat hey m8. I have an idea for a game. I will write it in java and then rewrite it in rust. I would like for you to join in on the production. It is a game like chess where you advance on a grid with warriors. Instead of working with medivial personas you work with Soldiers on a battlefield. Are you in?

EpicGamer007 (540)

@Jakman, maybe... im in class rite now, maybe talk later.

DynamicSquid (3558)

Hi! Quick question, I'm learning Rust rn, but I don't know how to import rand::Rng?

DungeonMaster00 (130)

the real braindead script kiddies are the ones on scratch a lot

Jakman (451)

@rediar i am a reverse engineer my son. If you want a t shirt go to the nearest mall

JosephSanthosh (1181)

@Jakman: ...is something for you braindead script kiddies.

@JosephSanthosh : I like that!

HahaYes (1212)

@JosephSanthosh yeah suit your self fid XD

JosephSanthosh (1181)

Haha you're literally making fun of yourself. @HahaYes

HahaYes (1212)

@JosephSanthosh heh we are gonna play like that? Calls me a kid. Ah..... I guess I'll use the power of the report

JosephSanthosh (1181)


Sure! Go ahead but where is the kid???

CodingCactus (3010)

@HahaYes don't report things like that again

JosephSanthosh (1181)

Incorrect! Fid = fiddle and fiddle = violin. A fiddle is a playful version of a violin, so calling someone a fid is calling them playful in a non-insulting way. @HahaYes

HahaYes (1212)

@CodingCactus I actually didn't know whether to take this as a insult or not. So I was really confused. I assumed fid was something bad but I can't be sure...

CodingCactus (3010)

@HahaYes ¯\_( ͠° ͟ʖ °͠ )_/¯ honestly, childish insults like that are alright as long as it is only once or twice.

JosephSanthosh (1181)

It isn't even an insult !!! It's a compliment to someone who's good in orchestra!!! What even??? @CodingCactus @HahaYes

CodingCactus (3010)

¯\_( ͡° ͜ʖ ͡°)_/¯

JosephSanthosh (1181)

@CodingCactus That face really creeps me out!

HahaYes (1212)

@JosephSanthosh bro we'll both calm down then just forget about this situation

HahaYes (1212)

@Jakman Thank you, yours truely

JosephSanthosh (1181)

My pleasure, With Love and Stupidity ~Joseph @HahaYes @Jakman I don't think this is an argument, more like a mistaken compliment.

k9chelsea2 (646)

nice quite short yet descriptive