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...
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 ...
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 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
...
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("{:...
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’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...
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...
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[:])
...
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...
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("...
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...
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 ...
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...