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

How to Use Variadic Functions in Golang

Variadic Functions Tutorial with Examples in Go. Variadic Function A variadic function is one that can be called with varying numbers of arguments. The most familiar examples are fmt.Printf and its variants. package main import "fmt" func add(v...
Patcher56

How to Add Two Numbers in Go

An example program using numbers. Integers And Floating Point Numbers Go has several different types to represent numbers. Generally we split numbers into two different kinds: integers and floating-point numbers. Make a main.go file containing the ...
pooriabt

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 Extract All the Numbers Contained in a String in Python

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

How to Generate Random Integers Between 0 and 9 in Python

In Python, there are 3 ways to generate random integers between 0 and 9. Using randrange Method The random.randrange(start, stop[, step]) method returns a randomly selected element from range(start, stop, step). For example, #!/usr/bin/python3 ...
Patcher56

How to Limit Floats to Two Decimal Points in Python

In Python, there are 4 ways to limit floats to two decimal points. Using format Method You can use str.format() function to limit floats, it really simple. For example, #!/usr/bin/python3 # -*- coding: utf8 -*- f = 13.949999999999999 print("{:...
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

Built-in Types in Python

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

How to generate a random string in Go

Creating Random Strings of a fixed length in Go. Using rand.Int63 Function Int63 returns a non-negative pseudo-random 63-bit integer as an int64 from the default Source. package main import ( "fmt" "math/rand" "time" ) const letters = "a...
ada

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

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 Convert string to integer type in Go

The most common numeric conversions are Atoi.strconv.Atoi Function Package strconv implements conversions to and from string representations of basic data types. package main import ( "fmt" "strconv" ) func main() { i, err := strconv.Atoi("...
pooriabt

How to use the kill command in Linux

terminate a process. kill is a command that is used in several popular operating systems to send signals to running processes. The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TE...

How to use the curl command in Linux

command line tool and library for transferring data with URLs. cURL (pronounced 'curl') is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name ...

How to use the cat command in Linux

Concatenate FILE(s), or standard input, to standard output. The cat command (short for “concatenate”) lists the contents of files to the terminal window. This is faster than opening the file in an editor, and there’s no chance you can accidentally a...