In Python, there are 2 ways to make a list of alphabet characters.
Using string Module
The string.ascii_lowercase is a pre-initialized string used as string constant. In Python, string ascii_lowercase will give the lowercase letters ‘abcdefghijklmno...
In Python, there are 2 ways to extract all the numbers contained in a string.
Using List Comprehension
List comprehensions provide a concise way to create lists.
If you only want to extract only positive integers, try the following:
#!/usr/bin/...
In Python, there are 4 ways to remove a trailing newline.
Using rstrip Method
The str.rstrip() method returns a copy of the string with trailing characters removed. For example,
#!/usr/bin/python3
s = "\nab c\r\n"
# str.rstrip([chars])
n = s....
In Python, there are 2 ways to get the current time.
Using datetime Module
The datetime module supplies classes for manipulating dates and times. See the following example:
#!/usr/bin/python3
# -*- coding: utf8 -*-
# Import module
import datet...
In Golang, there are 2 ways to install Go in Linux.Download Packages
Download packages for Windows 64-bit, macOS, Linux, and more.
Go install
Linux
Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extr...
In Rust, there are 3 ways to support For Loop expression.Using while Expression
A while loop begins by evaluating the boolean loop conditional operand.
fn main() {
let mut i = 0;
while i < 3 {
println!("{}", i);
i += 1;
}
// Vec
...
In Python, there are 3 ways to read a file line-by-line.
Using For Loop
For reading lines from a file, you can loop over the file object. This is memory efficient, fast, and leads to simple code:
#!/usr/bin/python3
# -*- coding: utf8 -*-
# read a...
Rust String Formatting and Printing Best Practices.Using println!
Prints to the standard output, with a newline. Use the format! syntax to write data to the standard output. See std::fmt for more information.
fn main() {
let name = "Bob";
pri...
In Rust, there are two ways to install rust in Linux.Running the following in your terminal
If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
3 ways to convert int64 to string in Golang.Using strconv.Itoa Function
The code snippet below shows how to convert an int to a string using the Itoa function.
package main
import (
"fmt"
"strconv"
)
func main() {
s := strconv.Itoa(100)
f...
Python String Formatting Best Practices.Fancier Output Formatting
To use formatted string literals, begin a string with f or F before the opening quotation mark or triple quotation mark. Inside this string, you can write a Python expression between {...
String Constants Best Practice.String Constants in Python
The constants defined in this module are:
String constants:
string.ascii_lettersThe concatenation of the ascii_lowercase and ascii_uppercase constants described below. This value is not locale...
Converting Json to string in Python.Decoding JSON
To convert string to json in Python, use the json.loads() function. The json.loads() is a built-in Python function that accepts a valid json string and returns a dictionary to access all elements. The...
Python’s Core Data Types.Core Data Types
The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions.
Built-in objects preview:
Object type:
Numbersint, float, complex.Strings'spam', "Bob's", b'a\x01c', u'sp\xc4m...
List of Golang Keywords.
Keywords
The following keywords are reserved and may not be used as identifiers.
break default func interface select
case defer go map struct
chan else goto package switch
const ...