म
MarathiCodeby Sprout Tech
Documentation topicsBuilt-in Functions
MarathiCode v0.2.0

Built-in Functions

छापा, लांबी, जोडा, वाचा, संख्या

NameUseResult
छापा(x)Prints x on its own line. A statement (keyword), not a function.No value
लांबी(x)Length of a list or string (in Unicode code points)A number
जोडा(यादी, x)Adds x to the end of the listThe same list
वाचा()Reads the next line of inputA string, or रिक्त when input has run out
संख्या(x)Converts text such as "42" or "-३.५" to a numberA number

छापा

छापा takes exactly one expression. To print several values, join them with +. Because it is a statement, it cannot be used inside an expression.

print.mr
चल नाव = "सई"
चल वय = 12
छापा(नाव + " चे वय " + वय)
छापा(10 + 20 * 3)
छापा(खरे)
छापा([1, "दोन"])
Output (आउटपुट)
सई चे वय 12
70
खरे
[1, "दोन"]

लांबी

length.mr
छापा(लांबी([1, 2, 3]))
छापा(लांबी("नमस्कार"))
छापा(लांबी([]))
Output (आउटपुट)
3
7
0

जोडा

जोडा changes the list it is given. It is usually called as a statement:

append.mr
चल वर्ग = []
साठी (i = 1; i <= 4; i = i + 1) {
    जोडा(वर्ग, i * i)
}
छापा(वर्ग)
Output (आउटपुट)
[1, 4, 9, 16]

वाचा and संख्या

वाचा() returns the next line of input as a string, without its line break. When there is no input left it returns रिक्त. In the command line the input comes from the keyboard or a redirected file; in the Playground it comes from the Input box. Input is always text, so use संख्या to turn it into a number. संख्या accepts ASCII or Devanagari digits, an optional minus sign and surrounding spaces.

input.mr
चल नाव = वाचा()
चल वय = संख्या(वाचा())
छापा("नमस्कार, " + नाव)
छापा("पुढच्या वर्षी वय: " + (वय + 1))
Input (इनपुट)
सई
१२
Output (आउटपुट)
नमस्कार, सई
पुढच्या वर्षी वय: 13
read_all.mr
चल बेरीज = 0
चल ओळ = वाचा()
पर्यंत ओळ != रिक्त {
    बेरीज = बेरीज + संख्या(ओळ)
    ओळ = वाचा()
}
छापा("एकूण: " + बेरीज)
Input (इनपुट)
10
20
30
Output (आउटपुट)
एकूण: 60
Calling a built-in with the wrong number or kind of arguments is a runtime error, for exampleलांबी(5), जोडा("मजकूर", 1) or संख्या("बारा").