All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Make a List of Alphabet Characters in Python

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...
Patcher56

How to Check if a String Contains Whitespace in Rust

In Rust, there are 2 ways to check if a string contains whitespace. Using char::is_whitespace char::is_whitespace returns true if the character has the Unicode White_Space property. You can pass char::is_whitespace to .contains(): fn main() { ...
Unused

How to Remove all Whitespace in a String in Python

In Python, there are 3 ways to remove all whitespace in a string. Using str.replace Function The str.replace(x) function returns a copy of the string with all occurrences of substring old replaced by new. See the following example: #!/usr/bin/p...
pooriabt

How to Prettyprint a JSON File in Python

In Python, there are 2 ways to prettyprint a JSON file. Using json module The json module already implements some basic pretty printing in the dump and dumps functions, with the indent parameter that specifies how many spaces to indent by: #!/us...
Patcher56

How to Remove a Trailing Newline in Python

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....
Tomoki

How to Trim Leading and Trailing White Spaces of a String in Go

In Golang, there are 3 ways to trim leading and trailing white spaces of a string. Using strings.TrimSpace Function The easiest way to trim leading and trailing white spaces of a string in Golang. For example, package main import ( "fmt" "...
Tomoki

How to Read a File Line-by-Line in Python

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...
pooriabt

How to create a multiline string in Rust

In Rust, there are 4 ways to create multiple lines string.Using triple-quotes A string literal is a sequence of any Unicode characters enclosed within two U+0022 (double-quote) characters, with the exception of U+0022 itself, which must be escaped b...
Unused

How to convert an int to a string type in Go

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...
aweis

How to split a string into a slice in Go

Splitting a String into a Slice in Golang.Using strings.Split Function Use the strings.Split function to split a string into its comma separated values. package main import ( "fmt" "strings" ) func main() { s := "Japan,Germany" // func S...
Unused

How to use string constants in Python

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...
Tomoki

How to convert string to json in Python

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...
pooriabt

How to use fmt.Sprintf Function in Go

Format a string without printing in Go.Basics Package fmt implements formatted I/O with functions analogous to C's printf and scanf. The format 'verbs' are derived from C's but are simpler. fmt.Sprintf Sprintf formats according to a format specif...
Sambhav Khandelwal

How to use the diff command in Linux

Compare FILES line by line. You can use the diff command to show differences between two files, or each corresponding file in two directories. diff outputs differences between files line by line in any of several formats, selectable by command line o...

How to use the cd command in Linux

The cd (“change directory”) command is used to change the current working directory in Linux and other Unix-like operating systems. The cd command, also known as chdir (change directory), is a command-line shell command used to change the current wo...