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) is just the file name but everything after that are the arguments. (sys.argv) and beyond. You can give functionality to these args via if statements such as
if sys.argv == read: print("reading!") else: 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): print("bang!")
import lib # lib is the name of the file so we must import from lib lib.shoot(17)
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.
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
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
@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?