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 Get the ASCII Value of a Character as an Int in Python

In Python, using the ord function is the easiest way to get the ASCII value of a character as an int. Using ord Function The ord() function returns an integer representing the Unicode code point of that character. To get the ASCII code of a charact...
Sambhav Khandelwal

How to Convert a Str to a &[u8] in Rust

In Rust, there are 2 ways to convert a str to a &[u8]. Using as_bytes Function The as_bytes() method converts a string slice to a byte slice. To convert the byte slice back into a string slice, use the from_utf8 function. See the following example...
aweis

How to Index Characters in a String in Go

In Golang, there are 2 ways to index characters in a string. Using individual characters In UTF-8, ASCII characters are single-byte corresponding to the first 128 Unicode characters. Strings behave like slices of bytes. A rune is an integer value i...
Patcher56

How to Pad a Numeric String with Zeros to the Left in Python

In Python, there are 3 ways to pad a numeric string with zeros to the left. Using zfill Method The str.zfill(width) method returns a copy of the string left filled with ASCII '0' digits to make a string of length width. For example, #!/usr/bin/...
Patcher56

How To Generate a Random String in Python

In Python, there are 3 ways to generate a random string.Using List Comprehension List comprehensions provide a concise way to create lists. See the following example: #!/usr/bin/python3 # -*- coding: utf8 -*- # Import module import random impor...
Sambhav Khandelwal

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 define python source code encodings

Correct way to define Python source code encoding.PEP 263 Python will default to ASCII as standard encoding if no other encoding hints are given. PEP 263 defines how to declare Python source code encoding. Using Coding To define a source code encodin...
Tomoki

How to fetch data from url in Python

Fetch Internet Resources Using The urllib Package.Fetching URLs The simplest way to use urllib.request is as follows: #!/usr/bin/env python3 # Import datetime module import urllib.request with urllib.request.urlopen('https://google.com') as respon...
pooriabt

How to format a string in Python

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 {...
Sambhav Khandelwal

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 get a substring from a string in Go

Extracting substrings in Go.Using the slice syntax A slice is formed by specifying two indices, a low and high bound, separated by a colon: // a[low : high] s := "Hello,世界" // e fmt.Println(s[1:2]) fmt.Println(s[1:]) // Hello,世界 fmt.Println(s[:]) ...
Patcher56