mirror of
https://github.com/LeCoupa/awesome-cheatsheets.git
synced 2026-01-27 21:58:02 -08:00
Compare commits
4 Commits
bd088f1caf
...
24000cc742
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24000cc742 | ||
|
|
88e5be6e4b | ||
|
|
2f9037b24e | ||
|
|
b8962db7ad |
@@ -88,7 +88,7 @@ CHEATSHEET C#
|
|||||||
string newStr = oldStr.Replace("old","new");
|
string newStr = oldStr.Replace("old","new");
|
||||||
|
|
||||||
//IndexOf
|
//IndexOf
|
||||||
//Finds the first ocurrence of a string in a larger string
|
//Finds the first occurrence of a string in a larger string
|
||||||
//Returns -1 if the string is not found
|
//Returns -1 if the string is not found
|
||||||
String.IndexOf(val, start, num)
|
String.IndexOf(val, start, num)
|
||||||
val - string to search for
|
val - string to search for
|
||||||
@@ -102,7 +102,7 @@ CHEATSHEET C#
|
|||||||
String.Split(Char[]);
|
String.Split(Char[]);
|
||||||
|
|
||||||
//ToCharArray
|
//ToCharArray
|
||||||
//Places selected characteres in a string in a char array
|
//Places selected characters in a string in a char array
|
||||||
String str = "AaBbCcDd";
|
String str = "AaBbCcDd";
|
||||||
//create array of 8 vowels
|
//create array of 8 vowels
|
||||||
var chars = str.ToCharArray();
|
var chars = str.ToCharArray();
|
||||||
@@ -135,7 +135,7 @@ CHEATSHEET C#
|
|||||||
|
|
||||||
6.1 TimeSpan Constructor
|
6.1 TimeSpan Constructor
|
||||||
|
|
||||||
TimpeSpan(hour, minute, sec)
|
TimeSpan(hour, minute, sec)
|
||||||
|
|
||||||
TimeSpan timeS = new TimeSpan(10, 14, 50);
|
TimeSpan timeS = new TimeSpan(10, 14, 50);
|
||||||
TimeSpan timeS_Hours = TimeSpan.FromDays(3640);
|
TimeSpan timeS_Hours = TimeSpan.FromDays(3640);
|
||||||
@@ -144,8 +144,8 @@ CHEATSHEET C#
|
|||||||
|
|
||||||
Format item syntax: {index[,alignment][:format string]}
|
Format item syntax: {index[,alignment][:format string]}
|
||||||
index - Specifies element in list of values to which format is applied
|
index - Specifies element in list of values to which format is applied
|
||||||
aligment - Indicates minimun width (in characters) to display value
|
alignment - Indicates minimum width (in characters) to display value
|
||||||
format string - Contains the code which specififes the format of the displayed value
|
format string - Contains the code which specifies the format of the displayed value
|
||||||
|
|
||||||
7.1 Numeric
|
7.1 Numeric
|
||||||
|
|
||||||
@@ -293,7 +293,7 @@ CHEATSHEET C#
|
|||||||
[access modifier] className (parameters) [:initializer]
|
[access modifier] className (parameters) [:initializer]
|
||||||
|
|
||||||
initializer -base calls constructor in base class.
|
initializer -base calls constructor in base class.
|
||||||
this calls constuctor within class.
|
this calls constructor within class.
|
||||||
|
|
||||||
public class nameClass : Initializer {
|
public class nameClass : Initializer {
|
||||||
public className(dataType param1 , dataType param2, ...) : base(param1, param2)
|
public className(dataType param1 , dataType param2, ...) : base(param1, param2)
|
||||||
@@ -313,8 +313,8 @@ CHEATSHEET C#
|
|||||||
abstract – must be implemented by subclass
|
abstract – must be implemented by subclass
|
||||||
|
|
||||||
Passing parameters:
|
Passing parameters:
|
||||||
1. By default, parametres are passed by value
|
1. By default, parameters are passed by value
|
||||||
2. Passing by reference: ref, in and out modifers
|
2. Passing by reference: ref, in and out modifiers
|
||||||
|
|
||||||
To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier
|
To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier
|
||||||
|
|
||||||
|
|||||||
@@ -524,14 +524,14 @@ Cyan='\033[0;36m' # Cyan
|
|||||||
White='\033[0;97m' # White
|
White='\033[0;97m' # White
|
||||||
|
|
||||||
# Additional colors
|
# Additional colors
|
||||||
LGrey='\033[0;37m' # Ligth Gray
|
LGrey='\033[0;37m' # Light Gray
|
||||||
DGrey='\033[0;90m' # Dark Gray
|
DGrey='\033[0;90m' # Dark Gray
|
||||||
LRed='\033[0;91m' # Ligth Red
|
LRed='\033[0;91m' # Light Red
|
||||||
LGreen='\033[0;92m' # Ligth Green
|
LGreen='\033[0;92m' # Light Green
|
||||||
LYellow='\033[0;93m'# Ligth Yellow
|
LYellow='\033[0;93m'# Light Yellow
|
||||||
LBlue='\033[0;94m' # Ligth Blue
|
LBlue='\033[0;94m' # Light Blue
|
||||||
LPurple='\033[0;95m'# Light Purple
|
LPurple='\033[0;95m'# Light Purple
|
||||||
LCyan='\033[0;96m' # Ligth Cyan
|
LCyan='\033[0;96m' # Light Cyan
|
||||||
|
|
||||||
|
|
||||||
# Bold
|
# Bold
|
||||||
|
|||||||
@@ -397,8 +397,8 @@ d, t := doubleAndTriple(5)
|
|||||||
_, t := doubleAndTriple(3)
|
_, t := doubleAndTriple(3)
|
||||||
// t = 9
|
// t = 9
|
||||||
|
|
||||||
// Functions can defer commands. Defered commands are
|
// Functions can defer commands. Deferred commands are
|
||||||
// runned in a stack order after the execution and
|
// ran in a stack order after the execution and
|
||||||
// returning of a function
|
// returning of a function
|
||||||
var aux = 0
|
var aux = 0
|
||||||
|
|
||||||
@@ -488,7 +488,7 @@ person3.Age // 0
|
|||||||
|
|
||||||
## Maps
|
## Maps
|
||||||
|
|
||||||
Maps are data structures that holds values assigneds to a key.
|
Maps are data structures that holds values assigned to a key.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Declaring a map
|
// Declaring a map
|
||||||
@@ -508,7 +508,7 @@ newYork // "EUA"
|
|||||||
// Delete
|
// Delete
|
||||||
delete(cities, "NY")
|
delete(cities, "NY")
|
||||||
|
|
||||||
// Check if a key is setted
|
// Check if a key is set
|
||||||
value, ok := cities["NY"]
|
value, ok := cities["NY"]
|
||||||
ok // false
|
ok // false
|
||||||
value // ""
|
value // ""
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ for(dataType item : array) {
|
|||||||
//Declare a variable, object name
|
//Declare a variable, object name
|
||||||
String s;
|
String s;
|
||||||
|
|
||||||
//Invoke a contructor to create an object
|
//Invoke a constructor to create an object
|
||||||
s = new String ("Hello World");
|
s = new String ("Hello World");
|
||||||
|
|
||||||
//Invoke an instance method that operates on the object's value
|
//Invoke an instance method that operates on the object's value
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Exit the file, string inside get's echo'ed
|
// Exit the file, string inside get's echo'ed
|
||||||
die("This file is not ment to be ran. ¯\_(ツ)_/¯");
|
die("This file is not meant to be ran. ¯\_(ツ)_/¯");
|
||||||
exit("This file is not ment to be ran. ¯\_(ツ)_/¯");
|
exit("This file is not meant to be ran. ¯\_(ツ)_/¯");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Printing
|
* Printing
|
||||||
@@ -17,7 +17,7 @@ var_dump($arr); // Print anything, with type hints for any value and sizes
|
|||||||
$string = 'Awesome cheatsheets';
|
$string = 'Awesome cheatsheets';
|
||||||
|
|
||||||
str_contains($string, 'cheat'); // Find if the string contains the specified string (PHP >= 8.0)
|
str_contains($string, 'cheat'); // Find if the string contains the specified string (PHP >= 8.0)
|
||||||
str_replace('Awesome', 'Bonjour', $string); // Replace all occurence
|
str_replace('Awesome', 'Bonjour', $string); // Replace all occurrence
|
||||||
strcmp($string, 'Awesome cheatsheets'); // Compare two strings
|
strcmp($string, 'Awesome cheatsheets'); // Compare two strings
|
||||||
strpos($string, 'a', 0); // Get position in the string
|
strpos($string, 'a', 0); // Get position in the string
|
||||||
str_split($string, 2); // Split the string
|
str_split($string, 2); // Split the string
|
||||||
@@ -541,7 +541,7 @@ u Pattern is treated as UTF-8
|
|||||||
\w Any "word" character (a-z 0-9 _)
|
\w Any "word" character (a-z 0-9 _)
|
||||||
\W Any non "word" character
|
\W Any non "word" character
|
||||||
\s Whitespace (space, tab CRLF)
|
\s Whitespace (space, tab CRLF)
|
||||||
\S Any non whitepsace character
|
\S Any non whitespace character
|
||||||
\d Digits (0-9)
|
\d Digits (0-9)
|
||||||
\D Any non digit character
|
\D Any non digit character
|
||||||
. (Period) - Any character except newline
|
. (Period) - Any character except newline
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
| import | import libraries/modules/packages | import |
|
| import | import libraries/modules/packages | import |
|
||||||
| from | import specific function/classes from modules/packages | import |
|
| from | import specific function/classes from modules/packages | import |
|
||||||
| try | this block will be tried to get executed | exception handling |
|
| try | this block will be tried to get executed | exception handling |
|
||||||
| except | is any exception/error has occured it'll be executed | exception handling |
|
| except | is any exception/error has occurred it'll be executed | exception handling |
|
||||||
| finally | It'll be executed no matter exception occurs or not | exception handling |
|
| finally | It'll be executed no matter exception occurs or not | exception handling |
|
||||||
| raise | throws any specific error/exception | exception handling |
|
| raise | throws any specific error/exception | exception handling |
|
||||||
| assert | throws an AssertionError if condition is false | exception handling |
|
| assert | throws an AssertionError if condition is false | exception handling |
|
||||||
|
|||||||
86
languages/python.py
Normal file
86
languages/python.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
"""
|
||||||
|
Python3 Programming Language Cheatsheet
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Basics: ###
|
||||||
|
|
||||||
|
# Variables -- Python uses variables to define things that are subject to change.
|
||||||
|
# Operators -- There are several type of operators available in Python.
|
||||||
|
# Arithmetic operators:
|
||||||
|
# + ----------> Addition Operator
|
||||||
|
# - ----------> Subtraction Operator
|
||||||
|
# * ----------> Multiplication Operator
|
||||||
|
# / ----------> Division Operator
|
||||||
|
# % ----------> Modulus Operator
|
||||||
|
# ** ----------> Exponent Operator
|
||||||
|
# // ----------> Floor division Operator
|
||||||
|
|
||||||
|
# Comparision Operators:
|
||||||
|
# == ----------> Equals
|
||||||
|
# != ----------> Not equal to
|
||||||
|
# > ----------> Greater than
|
||||||
|
# < ----------> Less than
|
||||||
|
# >= ----------> Greater than or equal to
|
||||||
|
# <= ----------> Less than or equal to
|
||||||
|
|
||||||
|
# Assignment Operators:
|
||||||
|
# = ----------> Assigns value
|
||||||
|
# += ----------> Shorthand for addition to itself
|
||||||
|
# -= ----------> Shorthand for subtraction to itself
|
||||||
|
# *= ----------> Shorthand for multiplication to itself
|
||||||
|
# /= ----------> Shorthand for division to itself
|
||||||
|
# %= ----------> Shorthand for modulus of itself
|
||||||
|
# **= ----------> Shorthand for exponent of itself
|
||||||
|
# //= ----------> Shorthand for floor division to itself
|
||||||
|
|
||||||
|
# Bitwise Operators:
|
||||||
|
# & ----------> Binary AND
|
||||||
|
# | ----------> Binary OR
|
||||||
|
# ^ ----------> Binary XOR
|
||||||
|
# ~ ----------> Binary NOT
|
||||||
|
# << ----------> Binary left shift
|
||||||
|
# >> ----------> Binary Right Shift
|
||||||
|
|
||||||
|
|
||||||
|
# Strings -- Strings in python are denoted by either '' or "". Some list operations are:
|
||||||
|
# ex: a = "Manoj"
|
||||||
|
# a[0] =>'M'
|
||||||
|
# a[1] => 'a'
|
||||||
|
# a[1:] => Will print rest of characters from 1 to other
|
||||||
|
# a[:3] => Will print 0 to 2nd position
|
||||||
|
# a[:] => Will print whole string
|
||||||
|
# a[:-1] => Grab everything but the last letter
|
||||||
|
# a[::2] => Grab everything but go in step sizes of 2
|
||||||
|
# a[::-1] => We can use this to print a string backwards
|
||||||
|
|
||||||
|
##### Strings have a property named immutability. It means once a string is created, the elements within it cann't be changed or replaced.
|
||||||
|
##### We can use multiplication symbol to create repetition. ex: letter = 'z', letter*10 will print 'zzzzzzzzzz'.
|
||||||
|
##### Similarly there are many methods that are applicable on strings:
|
||||||
|
# ex: a = 'Hello'
|
||||||
|
# a.upper() => converts string into upper case ==> 'HELLO'
|
||||||
|
# a.lower() => converts string into lower case ==> 'hello'
|
||||||
|
# a.title() => title case a string ==> 'Hello'
|
||||||
|
# a.rstrip() => Right trim white spaces
|
||||||
|
# a.lstrip() => Left trim white spaces
|
||||||
|
# a.strip() => completely trim the white spaces
|
||||||
|
# a.split() => split a string by blank spaces
|
||||||
|
# a.split("value") => split the string after some specific value
|
||||||
|
# a.isalnum() => True if string consists of only alphanum characters (No symbols).
|
||||||
|
# a.isalpha() => True if string consists of only alphabetic characters (No symbols).
|
||||||
|
# a.islower() => True if string's alphabetic characters are all lower case.
|
||||||
|
# a.isnumeric() => True if string consists of only numeric characters.
|
||||||
|
# a.isspace() => True if string consists of only whitespace characters.
|
||||||
|
# a.istitle() => True if string is in title case
|
||||||
|
# a.isupper() => True if string's alphabetic characters are all upper case.
|
||||||
|
|
||||||
|
##### Some other useful string methods or functions that are available in python are:
|
||||||
|
# .replace("first_string", "second_string") => first_string will be replaced by second_string
|
||||||
|
# .startswith("") => search for a particular character in the starting of a string
|
||||||
|
# .endswith("") => search for a particular character in the end of a string
|
||||||
|
# .capitalize() => capitalize the first word of the string
|
||||||
|
# .swapcase() => swap the case of caharacter in a string
|
||||||
|
|
||||||
|
|
||||||
|
# Lists -- [a1, a2, "Some String", [b1, "some other string"]], This is an example of the list.
|
||||||
|
# There are several List Operations like
|
||||||
|
# a =
|
||||||
Reference in New Issue
Block a user